home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 1999 August / SGI Freeware 1999 August.iso / dist / fw_flex.idb / usr / freeware / catman / u_man / cat1 / flex.Z / flex
Encoding:
Text File  |  1998-05-21  |  155.5 KB  |  3,697 lines

  1.  
  2.  
  3.  
  4.      FFFFLLLLEEEEXXXX((((1111))))         VVVVeeeerrrrssssiiiioooonnnn 2222....5555 ((((AAAApppprrrriiiillll 1111999999995555))))           FFFFLLLLEEEEXXXX((((1111))))
  5.  
  6.  
  7.  
  8.      NNNNAAAAMMMMEEEE
  9.       flex - fast lexical analyzer generator
  10.  
  11.      SSSSYYYYNNNNOOOOPPPPSSSSIIIISSSS
  12.       fffflllleeeexxxx [[[[----bbbbccccddddffffhhhhiiiillllnnnnppppssssttttvvvvwwwwBBBBFFFFIIIILLLLTTTTVVVV77778888++++???? ----CCCC[[[[aaaaeeeeffffFFFFmmmmrrrr]]]] ----oooooooouuuuttttppppuuuutttt ----PPPPpppprrrreeeeffffiiiixxxx
  13.       ----SSSSsssskkkkeeeelllleeeettttoooonnnn]]]] [[[[--------hhhheeeellllpppp --------vvvveeeerrrrssssiiiioooonnnn]]]] [_f_i_l_e_n_a_m_e ...]
  14.  
  15.      OOOOVVVVEEEERRRRVVVVIIIIEEEEWWWW
  16.       This manual describes    _f_l_e_x, a    tool for generating programs
  17.       that perform pattern-matching    on text.  The manual includes
  18.       both tutorial    and reference sections:
  19.  
  20.           Description
  21.           a brief overview of the tool
  22.  
  23.           Some Simple Examples
  24.  
  25.           Format Of    The Input File
  26.  
  27.           Patterns
  28.           the extended regular expressions used    by flex
  29.  
  30.           How The Input Is Matched
  31.           the rules for    determining what has been matched
  32.  
  33.           Actions
  34.           how to specify what to do when a pattern is matched
  35.  
  36.           The Generated Scanner
  37.           details regarding the    scanner    that flex produces;
  38.           how to control the input source
  39.  
  40.           Start Conditions
  41.           introducing context into your    scanners, and
  42.           managing "mini-scanners"
  43.  
  44.           Multiple Input Buffers
  45.           how to manipulate multiple input sources; how    to
  46.           scan from strings instead of files
  47.  
  48.           End-of-file Rules
  49.           special rules    for matching the end of    the input
  50.  
  51.           Miscellaneous Macros
  52.           a summary of macros available    to the actions
  53.  
  54.           Values Available To The User
  55.           a summary of values available    to the actions
  56.  
  57.           Interfacing With Yacc
  58.           connecting flex scanners together with yacc parsers
  59.  
  60.  
  61.  
  62.  
  63.      Page 1                         (printed 5/18/98)
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.      FFFFLLLLEEEEXXXX((((1111))))         VVVVeeeerrrrssssiiiioooonnnn 2222....5555 ((((AAAApppprrrriiiillll 1111999999995555))))           FFFFLLLLEEEEXXXX((((1111))))
  71.  
  72.  
  73.  
  74.           Options
  75.           flex command-line options, and the "%option"
  76.           directive
  77.  
  78.           Performance Considerations
  79.           how to make your scanner go as fast as possible
  80.  
  81.           Generating C++ Scanners
  82.           the (experimental) facility for generating C++
  83.           scanner classes
  84.  
  85.           Incompatibilities    With Lex And POSIX
  86.           how flex differs from    AT&T lex and the POSIX lex
  87.           standard
  88.  
  89.           Diagnostics
  90.           those    error messages produced    by flex    (or scanners
  91.           it generates)    whose meanings might not be apparent
  92.  
  93.           Files
  94.           files    used by    flex
  95.  
  96.           Deficiencies / Bugs
  97.           known    problems with flex
  98.  
  99.           See Also
  100.           other    documentation, related tools
  101.  
  102.           Author
  103.           includes contact information
  104.  
  105.  
  106.      DDDDEEEESSSSCCCCRRRRIIIIPPPPTTTTIIIIOOOONNNN
  107.       _f_l_e_x is a tool for generating    _s_c_a_n_n_e_r_s: programs which
  108.       recognized lexical patterns in text.    _f_l_e_x reads the given
  109.       input    files, or its standard input if    no file    names are
  110.       given, for a description of a    scanner    to generate.  The
  111.       description is in the    form of    pairs of regular expressions
  112.       and C    code, called _r_u_l_e_s. _f_l_e_x generates as output a C
  113.       source file, lllleeeexxxx....yyyyyyyy....cccc,,,, which defines a routine yyyyyyyylllleeeexxxx(((()))).... This
  114.       file is compiled and linked with the ----llllffffllll library to produce
  115.       an executable.  When the executable is run, it analyzes its
  116.       input    for occurrences    of the regular expressions.  Whenever
  117.       it finds one,    it executes the    corresponding C    code.
  118.  
  119.      SSSSOOOOMMMMEEEE SSSSIIIIMMMMPPPPLLLLEEEE EEEEXXXXAAAAMMMMPPPPLLLLEEEESSSS
  120.       First    some simple examples to    get the    flavor of how one uses
  121.       _f_l_e_x.    The following _f_l_e_x input specifies a scanner which
  122.       whenever it encounters the string "username" will replace it
  123.       with the user's login    name:
  124.  
  125.           %%
  126.  
  127.  
  128.  
  129.      Page 2                         (printed 5/18/98)
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136.      FFFFLLLLEEEEXXXX((((1111))))         VVVVeeeerrrrssssiiiioooonnnn 2222....5555 ((((AAAApppprrrriiiillll 1111999999995555))))           FFFFLLLLEEEEXXXX((((1111))))
  137.  
  138.  
  139.  
  140.           username      printf( "%s",    getlogin() );
  141.  
  142.       By default, any text not matched by a    _f_l_e_x scanner is    copied
  143.       to the output, so the    net effect of this scanner is to copy
  144.       its input file to its    output with each occurrence of
  145.       "username" expanded.    In this    input, there is    just one rule.
  146.       "username" is    the _p_a_t_t_e_r_n and    the "printf" is    the _a_c_t_i_o_n.
  147.       The "%%" marks the beginning of the rules.
  148.  
  149.       Here's another simple    example:
  150.  
  151.               int num_lines = 0, num_chars = 0;
  152.  
  153.           %%
  154.           \n      ++num_lines; ++num_chars;
  155.           .          ++num_chars;
  156.  
  157.           %%
  158.           main()
  159.               {
  160.               yylex();
  161.               printf( "# of lines = %d,    # of chars = %d\n",
  162.                   num_lines, num_chars );
  163.               }
  164.  
  165.       This scanner counts the number of characters and the number
  166.       of lines in its input    (it produces no    output other than the
  167.       final    report on the counts).    The first line declares    two
  168.       globals, "num_lines" and "num_chars",    which are accessible
  169.       both inside yyyyyyyylllleeeexxxx(((()))) and in the mmmmaaaaiiiinnnn(((())))    routine    declared after
  170.       the second "%%".  There are two rules, one which matches a
  171.       newline ("\n") and increments    both the line count and    the
  172.       character count, and one which matches any character other
  173.       than a newline (indicated by the "." regular expression).
  174.  
  175.       A somewhat more complicated example:
  176.  
  177.           /* scanner for a toy Pascal-like language    */
  178.  
  179.           %{
  180.           /* need this for the call    to atof() below    */
  181.           #include <math.h>
  182.           %}
  183.  
  184.           DIGIT    [0-9]
  185.           ID       [a-z][a-z0-9]*
  186.  
  187.           %%
  188.  
  189.           {DIGIT}+      {
  190.               printf( "An integer: %s (%d)\n", yytext,
  191.                   atoi(    yytext ) );
  192.  
  193.  
  194.  
  195.      Page 3                         (printed 5/18/98)
  196.  
  197.  
  198.  
  199.  
  200.  
  201.  
  202.      FFFFLLLLEEEEXXXX((((1111))))         VVVVeeeerrrrssssiiiioooonnnn 2222....5555 ((((AAAApppprrrriiiillll 1111999999995555))))           FFFFLLLLEEEEXXXX((((1111))))
  203.  
  204.  
  205.  
  206.               }
  207.  
  208.           {DIGIT}+"."{DIGIT}*     {
  209.               printf( "A float: %s (%g)\n",    yytext,
  210.                   atof(    yytext ) );
  211.               }
  212.  
  213.           if|then|begin|end|procedure|function      {
  214.               printf( "A keyword: %s\n", yytext );
  215.               }
  216.  
  217.           {ID}      printf( "An identifier: %s\n", yytext    );
  218.  
  219.           "+"|"-"|"*"|"/"    printf(    "An operator: %s\n", yytext );
  220.  
  221.           "{"[^}\n]*"}"    /* eat up one-line comments */
  222.  
  223.           [    \t\n]+        /* eat up whitespace */
  224.  
  225.           .          printf( "Unrecognized    character: %s\n", yytext );
  226.  
  227.           %%
  228.  
  229.           main( argc, argv )
  230.           int argc;
  231.           char **argv;
  232.           {
  233.           ++argv, --argc;  /* skip over    program    name */
  234.           if ( argc > 0    )
  235.               yyin = fopen(    argv[0], "r" );
  236.           else
  237.               yyin = stdin;
  238.  
  239.           yylex();
  240.           }
  241.  
  242.       This is the beginnings of a simple scanner for a language
  243.       like Pascal.    It identifies different    types of _t_o_k_e_n_s    and
  244.       reports on what it has seen.
  245.  
  246.       The details of this example will be explained    in the
  247.       following sections.
  248.  
  249.      FFFFOOOORRRRMMMMAAAATTTT OOOOFFFF TTTTHHHHEEEE IIIINNNNPPPPUUUUTTTT FFFFIIIILLLLEEEE
  250.       The _f_l_e_x input file consists of three    sections, separated by
  251.       a line with just %%%%%%%% in it:
  252.  
  253.           definitions
  254.           %%
  255.           rules
  256.           %%
  257.           user code
  258.  
  259.  
  260.  
  261.      Page 4                         (printed 5/18/98)
  262.  
  263.  
  264.  
  265.  
  266.  
  267.  
  268.      FFFFLLLLEEEEXXXX((((1111))))         VVVVeeeerrrrssssiiiioooonnnn 2222....5555 ((((AAAApppprrrriiiillll 1111999999995555))))           FFFFLLLLEEEEXXXX((((1111))))
  269.  
  270.  
  271.  
  272.       The _d_e_f_i_n_i_t_i_o_n_s section contains declarations    of simple _n_a_m_e
  273.       definitions to simplify the scanner specification, and
  274.       declarations of _s_t_a_r_t    _c_o_n_d_i_t_i_o_n_s, which are explained    in a
  275.       later    section.
  276.  
  277.       Name definitions have    the form:
  278.  
  279.           name definition
  280.  
  281.       The "name" is    a word beginning with a    letter or an
  282.       underscore ('_') followed by zero or more letters, digits,
  283.       '_', or '-' (dash).  The definition is taken to begin    at the
  284.       first    non-white-space    character following the    name and
  285.       continuing to    the end    of the line.  The definition can
  286.       subsequently be referred to using "{name}", which will
  287.       expand to "(definition)".  For example,
  288.  
  289.           DIGIT    [0-9]
  290.           ID       [a-z][a-z0-9]*
  291.  
  292.       defines "DIGIT" to be    a regular expression which matches a
  293.       single digit,    and "ID" to be a regular expression which
  294.       matches a letter followed by zero-or-more letters-or-digits.
  295.       A subsequent reference to
  296.  
  297.           {DIGIT}+"."{DIGIT}*
  298.  
  299.       is identical to
  300.  
  301.           ([0-9])+"."([0-9])*
  302.  
  303.       and matches one-or-more digits followed by a '.' followed by
  304.       zero-or-more digits.
  305.  
  306.       The _r_u_l_e_s section of the _f_l_e_x    input contains a series    of
  307.       rules    of the form:
  308.  
  309.           pattern    action
  310.  
  311.       where    the pattern must be unindented and the action must
  312.       begin    on the same line.
  313.  
  314.       See below for    a further description of patterns and actions.
  315.  
  316.       Finally, the user code section is simply copied to lllleeeexxxx....yyyyyyyy....cccc
  317.       verbatim.  It    is used    for companion routines which call or
  318.       are called by    the scanner.  The presence of this section is
  319.       optional; if it is missing, the second %%%%%%%% in the input file
  320.       may be skipped, too.
  321.  
  322.       In the definitions and rules sections, any _i_n_d_e_n_t_e_d text or
  323.       text enclosed    in %%%%{{{{ and %%%%}}}} is    copied verbatim    to the output
  324.  
  325.  
  326.  
  327.      Page 5                         (printed 5/18/98)
  328.  
  329.  
  330.  
  331.  
  332.  
  333.  
  334.      FFFFLLLLEEEEXXXX((((1111))))         VVVVeeeerrrrssssiiiioooonnnn 2222....5555 ((((AAAApppprrrriiiillll 1111999999995555))))           FFFFLLLLEEEEXXXX((((1111))))
  335.  
  336.  
  337.  
  338.       (with    the %{}'s removed).  The %{}'s must appear unindented
  339.       on lines by themselves.
  340.  
  341.       In the rules section,    any indented or    %{} text appearing
  342.       before the first rule    may be used to declare variables which
  343.       are local to the scanning routine and    (after the
  344.       declarations)    code which is to be executed whenever the
  345.       scanning routine is entered.    Other indented or %{} text in
  346.       the rule section is still copied to the output, but its
  347.       meaning is not well-defined and it may well cause compile-
  348.       time errors (this feature is present for _P_O_S_I_X compliance;
  349.       see below for    other such features).
  350.  
  351.       In the definitions section (but not in the rules section),
  352.       an unindented    comment    (i.e., a line beginning    with "/*") is
  353.       also copied verbatim to the output up    to the next "*/".
  354.  
  355.      PPPPAAAATTTTTTTTEEEERRRRNNNNSSSS
  356.       The patterns in the input are    written    using an extended set
  357.       of regular expressions.  These are:
  358.  
  359.           x         match the character 'x'
  360.           .         any character (byte) except newline
  361.           [xyz]     a "character class"; in this case, the    pattern
  362.                matches either an 'x', a 'y', or a 'z'
  363.           [abj-oZ]     a "character class" with a range in it; matches
  364.                an 'a', a 'b', any letter from 'j' through 'o',
  365.                or a    'Z'
  366.           [^A-Z]     a "negated character class", i.e., any    character
  367.                but those in    the class.  In this case, any
  368.                character EXCEPT an uppercase letter.
  369.           [^A-Z\n]     any character EXCEPT an uppercase letter or
  370.                a newline
  371.           r*     zero or more r's, where r is any regular expression
  372.           r+     one or    more r's
  373.           r?     zero or one r's (that is, "an optional    r")
  374.           r{2,5}     anywhere from two to five r's
  375.           r{2,}     two or    more r's
  376.           r{4}     exactly 4 r's
  377.           {name}     the expansion of the "name" definition
  378.              (see above)
  379.           "[xyz]\"foo"
  380.              the literal string: [xyz]"foo
  381.           \X     if X is an 'a', 'b', 'f', 'n',    'r', 't', or 'v',
  382.                then    the ANSI-C interpretation of \x.
  383.                Otherwise, a    literal    'X' (used to escape
  384.                operators such as '*')
  385.           \0     a NUL character (ASCII    code 0)
  386.           \123     the character with octal value    123
  387.           \x2a     the character with hexadecimal    value 2a
  388.           (r)     match an r; parentheses are used to override
  389.                precedence (see below)
  390.  
  391.  
  392.  
  393.      Page 6                         (printed 5/18/98)
  394.  
  395.  
  396.  
  397.  
  398.  
  399.  
  400.      FFFFLLLLEEEEXXXX((((1111))))         VVVVeeeerrrrssssiiiioooonnnn 2222....5555 ((((AAAApppprrrriiiillll 1111999999995555))))           FFFFLLLLEEEEXXXX((((1111))))
  401.  
  402.  
  403.  
  404.           rs     the regular expression    r followed by the
  405.                regular expression s; called    "concatenation"
  406.  
  407.  
  408.           r|s     either    an r or    an s
  409.  
  410.  
  411.           r/s     an r but only if it is    followed by an s.  The
  412.                text    matched    by s is    included when determining
  413.                whether this    rule is    the "longest match",
  414.                but is then returned    to the input before
  415.                the action is executed.  So the action only
  416.                sees    the text matched by r.    This type
  417.                of pattern is called    trailing context".
  418.                (There are some combinations    of r/s that flex
  419.                cannot match    correctly; see notes in    the
  420.                Deficiencies    / Bugs section below regarding
  421.                "dangerous trailing context".)
  422.           ^r     an r, but only    at the beginning of a line (i.e.,
  423.                which just starting to scan,    or right after a
  424.                newline has been scanned).
  425.           r$     an r, but only    at the end of a    line (i.e., just
  426.                before a newline).  Equivalent to "r/\n".
  427.  
  428.              Note that flex's notion of "newline" is exactly
  429.              whatever the C    compiler used to compile flex
  430.              interprets '\n' as; in    particular, on some DOS
  431.              systems you must either filter    out \r's in the
  432.              input yourself, or explicitly use r/\r\n for "r$".
  433.  
  434.  
  435.           <s>r     an r, but only    in start condition s (see
  436.                below for discussion    of start conditions)
  437.           <s1,s2,s3>r
  438.              same, but in any of start conditions s1,
  439.                s2, or s3
  440.           <*>r     an r in any start condition, even an exclusive    one.
  441.  
  442.  
  443.           <<EOF>>     an end-of-file
  444.           <s1,s2><<EOF>>
  445.              an end-of-file    when in    start condition    s1 or s2
  446.  
  447.       Note that inside of a    character class, all regular
  448.       expression operators lose their special meaning except
  449.       escape ('\') and the character class operators, '-', ']',
  450.       and, at the beginning    of the class, '^'.
  451.  
  452.       The regular expressions listed above are grouped according
  453.       to precedence, from highest precedence at the    top to lowest
  454.       at the bottom.  Those    grouped    together have equal
  455.       precedence.  For example,
  456.  
  457.  
  458.  
  459.      Page 7                         (printed 5/18/98)
  460.  
  461.  
  462.  
  463.  
  464.  
  465.  
  466.      FFFFLLLLEEEEXXXX((((1111))))         VVVVeeeerrrrssssiiiioooonnnn 2222....5555 ((((AAAApppprrrriiiillll 1111999999995555))))           FFFFLLLLEEEEXXXX((((1111))))
  467.  
  468.  
  469.  
  470.           foo|bar*
  471.  
  472.       is the same as
  473.  
  474.           (foo)|(ba(r*))
  475.  
  476.       since    the '*'    operator has higher precedence than
  477.       concatenation, and concatenation higher than alternation
  478.       ('|').  This pattern therefore matches _e_i_t_h_e_r    the string
  479.       "foo"    _o_r the string "ba" followed by zero-or-more r's.  To
  480.       match    "foo" or zero-or-more "bar"'s, use:
  481.  
  482.           foo|(bar)*
  483.  
  484.       and to match zero-or-more "foo"'s-or-"bar"'s:
  485.  
  486.           (foo|bar)*
  487.  
  488.  
  489.       In addition to characters and    ranges of characters,
  490.       character classes can    also contain character class
  491.       _e_x_p_r_e_s_s_i_o_n_s. These are expressions enclosed inside [[[[::::    and ::::]]]]
  492.       delimiters (which themselves must appear between the '[' and
  493.       ']' of the character class; other elements may occur inside
  494.       the character    class, too).  The valid    expressions are:
  495.  
  496.           [:alnum:]    [:alpha:] [:blank:]
  497.           [:cntrl:]    [:digit:] [:graph:]
  498.           [:lower:]    [:print:] [:punct:]
  499.           [:space:]    [:upper:] [:xdigit:]
  500.  
  501.       These    expressions all    designate a set    of characters
  502.       equivalent to    the corresponding standard C iiiissssXXXXXXXXXXXX function.
  503.       For example, [[[[::::aaaallllnnnnuuuummmm::::]]]] designates those characters for which
  504.       iiiissssaaaallllnnnnuuuummmm(((()))) returns true - i.e., any alphabetic    or numeric.
  505.       Some systems don't provide iiiissssbbbbllllaaaannnnkkkk(((()))),,,,    so flex    defines
  506.       [[[[::::bbbbllllaaaannnnkkkk::::]]]] as a blank or a tab.
  507.  
  508.       For example, the following character classes are all
  509.       equivalent:
  510.  
  511.           [[:alnum:]]
  512.           [[:alpha:][:digit:]
  513.           [[:alpha:]0-9]
  514.           [a-zA-Z0-9]
  515.  
  516.       If your scanner is case-insensitive (the ----iiii flag), then
  517.       [[[[::::uuuuppppppppeeeerrrr::::]]]] and    [[[[::::lllloooowwwweeeerrrr::::]]]] are equivalent to [[[[::::aaaallllpppphhhhaaaa::::]]]]....
  518.  
  519.       Some notes on    patterns:
  520.  
  521.       -    A negated character class such as the example "[^A-Z]"
  522.  
  523.  
  524.  
  525.      Page 8                         (printed 5/18/98)
  526.  
  527.  
  528.  
  529.  
  530.  
  531.  
  532.      FFFFLLLLEEEEXXXX((((1111))))         VVVVeeeerrrrssssiiiioooonnnn 2222....5555 ((((AAAApppprrrriiiillll 1111999999995555))))           FFFFLLLLEEEEXXXX((((1111))))
  533.  
  534.  
  535.  
  536.            above _w_i_l_l _m_a_t_c_h    _a _n_e_w_l_i_n_e unless "\n" (or an
  537.            equivalent escape sequence) is one of the characters
  538.            explicitly present in the negated character class
  539.            (e.g., "[^A-Z\n]").  This is unlike how many other
  540.            regular expression tools    treat negated character
  541.            classes,    but unfortunately the inconsistency is
  542.            historically entrenched.     Matching newlines means that
  543.            a pattern like [^"]* can    match the entire input unless
  544.            there's another quote in    the input.
  545.  
  546.       -    A rule can have at most one instance of trailing
  547.            context (the '/'    operator or the    '$' operator).    The
  548.            start condition,    '^', and "<<EOF>>" patterns can    only
  549.            occur at    the beginning of a pattern, and, as well as
  550.            with '/'    and '$', cannot    be grouped inside parentheses.
  551.            A '^' which does    not occur at the beginning of a    rule
  552.            or a '$'    which does not occur at    the end    of a rule
  553.            loses its special properties and    is treated as a    normal
  554.            character.
  555.  
  556.            The following are illegal:
  557.  
  558.            foo/bar$
  559.            <sc1>foo<sc2>bar
  560.  
  561.            Note that the first of these, can be written
  562.            "foo/bar\n".
  563.  
  564.            The following will result in '$'    or '^' being treated
  565.            as a normal character:
  566.  
  567.            foo|(bar$)
  568.            foo|^bar
  569.  
  570.            If what's wanted    is a "foo" or a    bar-followed-by-a-
  571.            newline,    the following could be used (the special '|'
  572.            action is explained below):
  573.  
  574.            foo        |
  575.            bar$        /* action goes here    */
  576.  
  577.            A similar trick will work for matching a    foo or a bar-
  578.            at-the-beginning-of-a-line.
  579.  
  580.      HHHHOOOOWWWW TTTTHHHHEEEE IIIINNNNPPPPUUUUTTTT IIIISSSS MMMMAAAATTTTCCCCHHHHEEEEDDDD
  581.       When the generated scanner is    run, it    analyzes its input
  582.       looking for strings which match any of its patterns.    If it
  583.       finds    more than one match, it    takes the one matching the
  584.       most text (for trailing context rules, this includes the
  585.       length of the    trailing part, even though it will then    be
  586.       returned to the input).  If it finds two or more matches of
  587.       the same length, the rule listed first in the    _f_l_e_x input
  588.  
  589.  
  590.  
  591.      Page 9                         (printed 5/18/98)
  592.  
  593.  
  594.  
  595.  
  596.  
  597.  
  598.      FFFFLLLLEEEEXXXX((((1111))))         VVVVeeeerrrrssssiiiioooonnnn 2222....5555 ((((AAAApppprrrriiiillll 1111999999995555))))           FFFFLLLLEEEEXXXX((((1111))))
  599.  
  600.  
  601.  
  602.       file is chosen.
  603.  
  604.       Once the match is determined,    the text corresponding to the
  605.       match    (called    the _t_o_k_e_n) is made available in    the global
  606.       character pointer yyyyyyyytttteeeexxxxtttt,,,, and    its length in the global
  607.       integer yyyyyyyylllleeeennnngggg.... The _a_c_t_i_o_n corresponding to the matched
  608.       pattern is then executed (a more detailed description    of
  609.       actions follows), and    then the remaining input is scanned
  610.       for another match.
  611.  
  612.       If no    match is found,    then the _d_e_f_a_u_l_t _r_u_l_e is executed: the
  613.       next character in the    input is considered matched and    copied
  614.       to the standard output.  Thus, the simplest legal _f_l_e_x input
  615.       is:
  616.  
  617.           %%
  618.  
  619.       which    generates a scanner that simply    copies its input (one
  620.       character at a time) to its output.
  621.  
  622.       Note that yyyyyyyytttteeeexxxxtttt can be defined in two different ways:
  623.       either as a character    _p_o_i_n_t_e_r    or as a    character _a_r_r_a_y. You
  624.       can control which definition _f_l_e_x uses by including one of
  625.       the special directives %%%%ppppooooiiiinnnntttteeeerrrr or %%%%aaaarrrrrrrraaaayyyy in the first
  626.       (definitions)    section    of your    flex input.  The default is
  627.       %%%%ppppooooiiiinnnntttteeeerrrr,,,, unless you use the ----llll lex compatibility option, in
  628.       which    case yyyyyyyytttteeeexxxxtttt will be an array.  The advantage of    using
  629.       %%%%ppppooooiiiinnnntttteeeerrrr is substantially faster scanning and    no buffer
  630.       overflow when    matching very large tokens (unless you run out
  631.       of dynamic memory).  The disadvantage    is that    you are
  632.       restricted in    how your actions can modify yyyyyyyytttteeeexxxxtttt (see    the
  633.       next section), and calls to the uuuunnnnppppuuuutttt(((()))) function destroys
  634.       the present contents of yyyyyyyytttteeeexxxxtttt,,,, which    can be a considerable
  635.       porting headache when    moving between different _l_e_x versions.
  636.  
  637.       The advantage    of %%%%aaaarrrrrrrraaaayyyy is that you can then modify yyyyyyyytttteeeexxxxtttt
  638.       to your heart's content, and calls to    uuuunnnnppppuuuutttt(((())))    do not destroy
  639.       yyyyyyyytttteeeexxxxtttt (see below).  Furthermore, existing _l_e_x programs
  640.       sometimes access yyyyyyyytttteeeexxxxtttt externally using declarations    of the
  641.       form:
  642.           extern char yytext[];
  643.       This definition is erroneous when used with %%%%ppppooooiiiinnnntttteeeerrrr,,,,    but
  644.       correct for %%%%aaaarrrrrrrraaaayyyy....
  645.  
  646.       %%%%aaaarrrrrrrraaaayyyy defines yyyyyyyytttteeeexxxxtttt    to be an array of YYYYYYYYLLLLMMMMAAAAXXXX characters,
  647.       which    defaults to a fairly large value.  You can change the
  648.       size by simply #define'ing YYYYYYYYLLLLMMMMAAAAXXXX to a different value in
  649.       the first section of your _f_l_e_x input.     As mentioned above,
  650.       with %%%%ppppooooiiiinnnntttteeeerrrr    yytext grows dynamically to accommodate    large
  651.       tokens.  While this means your %%%%ppppooooiiiinnnntttteeeerrrr scanner can
  652.       accommodate very large tokens    (such as matching entire
  653.       blocks of comments), bear in mind that each time the scanner
  654.  
  655.  
  656.  
  657.      Page 10                         (printed 5/18/98)
  658.  
  659.  
  660.  
  661.  
  662.  
  663.  
  664.      FFFFLLLLEEEEXXXX((((1111))))         VVVVeeeerrrrssssiiiioooonnnn 2222....5555 ((((AAAApppprrrriiiillll 1111999999995555))))           FFFFLLLLEEEEXXXX((((1111))))
  665.  
  666.  
  667.  
  668.       must resize yyyyyyyytttteeeexxxxtttt it    also must rescan the entire token from
  669.       the beginning, so matching such tokens can prove slow.
  670.       yyyyyyyytttteeeexxxxtttt presently does    _n_o_t dynamically    grow if    a call to
  671.       uuuunnnnppppuuuutttt(((()))) results in too much text being pushed    back; instead,
  672.       a run-time error results.
  673.  
  674.       Also note that you cannot use    %%%%aaaarrrrrrrraaaayyyy with C++    scanner
  675.       classes (the cccc++++++++ option; see below).
  676.  
  677.      AAAACCCCTTTTIIIIOOOONNNNSSSS
  678.       Each pattern in a rule has a corresponding action, which can
  679.       be any arbitrary C statement.     The pattern ends at the first
  680.       non-escaped whitespace character; the    remainder of the line
  681.       is its action.  If the action    is empty, then when the
  682.       pattern is matched the input token is    simply discarded.  For
  683.       example, here    is the specification for a program which
  684.       deletes all occurrences of "zap me" from its input:
  685.  
  686.           %%
  687.           "zap me"
  688.  
  689.       (It will copy    all other characters in    the input to the
  690.       output since they will be matched by the default rule.)
  691.  
  692.       Here is a program which compresses multiple blanks and tabs
  693.       down to a single blank, and throws away whitespace found at
  694.       the end of a line:
  695.  
  696.           %%
  697.           [    \t]+        putchar( ' ' );
  698.           [    \t]+$        /* ignore this token */
  699.  
  700.  
  701.       If the action    contains a '{',    then the action    spans till the
  702.       balancing '}'    is found, and the action may cross multiple
  703.       lines.  _f_l_e_x knows about C strings and comments and won't be
  704.       fooled by braces found within    them, but also allows actions
  705.       to begin with    %%%%{{{{ and will consider the action    to be all the
  706.       text up to the next %%%%}}}} (regardless of    ordinary braces    inside
  707.       the action).
  708.  
  709.       An action consisting solely of a vertical bar    ('|') means
  710.       "same    as the action for the next rule."  See below for an
  711.       illustration.
  712.  
  713.       Actions can include arbitrary    C code,    including rrrreeeettttuuuurrrrnnnn
  714.       statements to    return a value to whatever routine called
  715.       yyyyyyyylllleeeexxxx(((()))).... Each    time yyyyyyyylllleeeexxxx(((()))) is    called it continues processing
  716.       tokens from where it last left off until it either reaches
  717.       the end of the file or executes a return.
  718.  
  719.       Actions are free to modify yyyyyyyytttteeeexxxxtttt except for lengthening it
  720.  
  721.  
  722.  
  723.      Page 11                         (printed 5/18/98)
  724.  
  725.  
  726.  
  727.  
  728.  
  729.  
  730.      FFFFLLLLEEEEXXXX((((1111))))         VVVVeeeerrrrssssiiiioooonnnn 2222....5555 ((((AAAApppprrrriiiillll 1111999999995555))))           FFFFLLLLEEEEXXXX((((1111))))
  731.  
  732.  
  733.  
  734.       (adding characters to    its end--these will overwrite later
  735.       characters in    the input stream).  This however does not
  736.       apply    when using %%%%aaaarrrrrrrraaaayyyy (see above); in that case, yyyyyyyytttteeeexxxxtttt
  737.       may be freely    modified in any    way.
  738.  
  739.       Actions are free to modify yyyyyyyylllleeeennnngggg except they    should not do
  740.       so if    the action also    includes use of    yyyyyyyymmmmoooorrrreeee(((()))) (see below).
  741.  
  742.       There    are a number of    special    directives which can be
  743.       included within an action:
  744.  
  745.       -    EEEECCCCHHHHOOOO copies yytext to the scanner's output.
  746.  
  747.       -    BBBBEEEEGGGGIIIINNNN followed by the name of a start condition places
  748.            the scanner in the corresponding    start condition    (see
  749.            below).
  750.  
  751.       -    RRRREEEEJJJJEEEECCCCTTTT directs the scanner to proceed on    to the "second
  752.            best" rule which    matched    the input (or a    prefix of the
  753.            input).    The rule is chosen as described    above in "How
  754.            the Input is Matched", and yyyyyyyytttteeeexxxxtttt and yyyyyyyylllleeeennnngggg set    up
  755.            appropriately.  It may either be    one which matched as
  756.            much text as the    originally chosen rule but came    later
  757.            in the _f_l_e_x input file, or one which matched less text.
  758.            For example, the    following will both count the words in
  759.            the input and call the routine special()    whenever
  760.            "frob" is seen:
  761.  
  762.                int word_count = 0;
  763.            %%
  764.  
  765.            frob           special(); REJECT;
  766.            [^ \t\n]+   ++word_count;
  767.  
  768.            Without the RRRREEEEJJJJEEEECCCCTTTT,,,, any "frob"'s    in the input would not
  769.            be counted as words, since the scanner normally
  770.            executes    only one action    per token.  Multiple RRRREEEEJJJJEEEECCCCTTTT''''ssss
  771.            are allowed, each one finding the next best choice to
  772.            the currently active rule.  For example,    when the
  773.            following scanner scans the token "abcd", it will write
  774.            "abcdabcaba" to the output:
  775.  
  776.            %%
  777.            a        |
  778.            ab        |
  779.            abc        |
  780.            abcd        ECHO; REJECT;
  781.            .|\n        /* eat up any unmatched character */
  782.  
  783.            (The first three    rules share the    fourth's action    since
  784.            they use    the special '|'    action.)  RRRREEEEJJJJEEEECCCCTTTT is a
  785.            particularly expensive feature in terms of scanner
  786.  
  787.  
  788.  
  789.      Page 12                         (printed 5/18/98)
  790.  
  791.  
  792.  
  793.  
  794.  
  795.  
  796.      FFFFLLLLEEEEXXXX((((1111))))         VVVVeeeerrrrssssiiiioooonnnn 2222....5555 ((((AAAApppprrrriiiillll 1111999999995555))))           FFFFLLLLEEEEXXXX((((1111))))
  797.  
  798.  
  799.  
  800.            performance; if it is used in _a_n_y of the    scanner's
  801.            actions it will slow down _a_l_l of    the scanner's
  802.            matching.  Furthermore, RRRREEEEJJJJEEEECCCCTTTT cannot be    used with the
  803.            -_C_f or -_C_F options (see below).
  804.  
  805.            Note also that unlike the other special actions,    RRRREEEEJJJJEEEECCCCTTTT
  806.            is a _b_r_a_n_c_h; code immediately following it in the
  807.            action will _n_o_t be executed.
  808.  
  809.       -    yyyyyyyymmmmoooorrrreeee(((())))    tells the scanner that the next    time it
  810.            matches a rule, the corresponding token should be
  811.            _a_p_p_e_n_d_e_d    onto the current value of yyyyyyyytttteeeexxxxtttt rather    than
  812.            replacing it.  For example, given the input "mega-
  813.            kludge" the following will write    "mega-mega-kludge" to
  814.            the output:
  815.  
  816.            %%
  817.            mega-    ECHO; yymore();
  818.            kludge   ECHO;
  819.  
  820.            First "mega-" is    matched    and echoed to the output.
  821.            Then "kludge" is    matched, but the previous "mega-" is
  822.            still hanging around at the beginning of    yyyyyyyytttteeeexxxxtttt so the
  823.            EEEECCCCHHHHOOOO for    the "kludge" rule will actually    write "mega-
  824.            kludge".
  825.  
  826.       Two notes regarding use of yyyyyyyymmmmoooorrrreeee(((()))).... First, yyyyyyyymmmmoooorrrreeee(((()))) depends
  827.       on the value of _y_y_l_e_n_g correctly reflecting the size of the
  828.       current token, so you    must not modify    _y_y_l_e_n_g if you are
  829.       using    yyyyyyyymmmmoooorrrreeee(((()))).... Second, the presence of yyyyyyyymmmmoooorrrreeee(((()))) in the
  830.       scanner's action entails a minor performance penalty in the
  831.       scanner's matching speed.
  832.  
  833.       -    yyyyyyyylllleeeessssssss((((nnnn)))) returns all but the first _n characters    of the
  834.            current token back to the input stream, where they will
  835.            be rescanned when the scanner looks for the next    match.
  836.            yyyyyyyytttteeeexxxxtttt and yyyyyyyylllleeeennnngggg are adjusted appropriately (e.g.,
  837.            yyyyyyyylllleeeennnngggg will now be equal    to _n ).     For example, on the
  838.            input "foobar" the following will write out
  839.            "foobarbar":
  840.  
  841.            %%
  842.            foobar    ECHO; yyless(3);
  843.            [a-z]+    ECHO;
  844.  
  845.            An argument of 0    to yyyyyyyylllleeeessssssss will cause the entire
  846.            current input string to be scanned again.  Unless
  847.            you've changed how the scanner will subsequently
  848.            process its input (using    BBBBEEEEGGGGIIIINNNN,,,, for example), this will
  849.            result in an endless loop.
  850.  
  851.       Note that yyyyyyyylllleeeessssssss is a    macro and can only be used in the flex
  852.  
  853.  
  854.  
  855.      Page 13                         (printed 5/18/98)
  856.  
  857.  
  858.  
  859.  
  860.  
  861.  
  862.      FFFFLLLLEEEEXXXX((((1111))))         VVVVeeeerrrrssssiiiioooonnnn 2222....5555 ((((AAAApppprrrriiiillll 1111999999995555))))           FFFFLLLLEEEEXXXX((((1111))))
  863.  
  864.  
  865.  
  866.       input    file, not from other source files.
  867.  
  868.       -    uuuunnnnppppuuuutttt((((cccc))))    puts the character _c back onto the input
  869.            stream.    It will    be the next character scanned.    The
  870.            following action    will take the current token and    cause
  871.            it to be    rescanned enclosed in parentheses.
  872.  
  873.            {
  874.            int i;
  875.            /* Copy yytext because unput() trashes yytext */
  876.            char    *yycopy    = strdup( yytext );
  877.            unput( ')' );
  878.            for ( i = yyleng - 1; i >= 0; --i )
  879.                unput( yycopy[i]    );
  880.            unput( '(' );
  881.            free( yycopy    );
  882.            }
  883.  
  884.            Note that since each uuuunnnnppppuuuutttt(((()))) puts the given character
  885.            back at the _b_e_g_i_n_n_i_n_g of    the input stream, pushing back
  886.            strings must be done back-to-front.
  887.  
  888.       An important potential problem when using uuuunnnnppppuuuutttt(((()))) is that if
  889.       you are using    %%%%ppppooooiiiinnnntttteeeerrrr (the default),    a call to uuuunnnnppppuuuutttt(((())))
  890.       _d_e_s_t_r_o_y_s the contents    of _y_y_t_e_x_t, starting with its rightmost
  891.       character and    devouring one character    to the left with each
  892.       call.     If you    need the value of yytext preserved after a
  893.       call to uuuunnnnppppuuuutttt(((()))) (as in the above example), you must either
  894.       first    copy it    elsewhere, or build your scanner using %%%%aaaarrrrrrrraaaayyyy
  895.       instead (see How The Input Is    Matched).
  896.  
  897.       Finally, note    that you cannot    put back EEEEOOOOFFFF to    attempt    to
  898.       mark the input stream    with an    end-of-file.
  899.  
  900.       -    iiiinnnnppppuuuutttt(((()))) reads the next character    from the input stream.
  901.            For example, the    following is one way to    eat up C
  902.            comments:
  903.  
  904.            %%
  905.            "/*"           {
  906.                    register    int c;
  907.  
  908.                    for ( ; ; )
  909.                    {
  910.                    while ( (c =    input()) != '*'    &&
  911.                        c !=    EOF )
  912.                        ;    /* eat up text of comment */
  913.  
  914.                    if (    c == '*' )
  915.                        {
  916.                        while ( (c = input()) ==    '*' )
  917.                        ;
  918.  
  919.  
  920.  
  921.      Page 14                         (printed 5/18/98)
  922.  
  923.  
  924.  
  925.  
  926.  
  927.  
  928.      FFFFLLLLEEEEXXXX((((1111))))         VVVVeeeerrrrssssiiiioooonnnn 2222....5555 ((((AAAApppprrrriiiillll 1111999999995555))))           FFFFLLLLEEEEXXXX((((1111))))
  929.  
  930.  
  931.  
  932.                        if ( c == '/' )
  933.                        break;    /*    found the end */
  934.                        }
  935.  
  936.                    if (    c == EOF )
  937.                        {
  938.                        error( "EOF in comment" );
  939.                        break;
  940.                        }
  941.                    }
  942.                    }
  943.  
  944.            (Note that if the scanner is compiled using CCCC++++++++,,,,    then
  945.            iiiinnnnppppuuuutttt(((()))) is instead referred to as yyyyyyyyiiiinnnnppppuuuutttt(((()))),,,, in order
  946.            to avoid    a name clash with the CCCC++++++++ stream by the    name
  947.            of _i_n_p_u_t.)
  948.  
  949.       -    YYYYYYYY____FFFFLLLLUUUUSSSSHHHH____BBBBUUUUFFFFFFFFEEEERRRR flushes the scanner's internal buffer
  950.            so that the next    time the scanner attempts to match a
  951.            token, it will first refill the buffer using YYYYYYYY____IIIINNNNPPPPUUUUTTTT
  952.            (see The    Generated Scanner, below).  This action    is a
  953.            special case of the more    general    yyyyyyyy____fffflllluuuusssshhhh____bbbbuuuuffffffffeeeerrrr(((())))
  954.            function, described below in the    section    Multiple Input
  955.            Buffers.
  956.  
  957.       -    yyyyyyyytttteeeerrrrmmmmiiiinnnnaaaatttteeee(((()))) can be used in lieu of a return statement
  958.            in an action.  It terminates the    scanner    and returns a
  959.            0 to the    scanner's caller, indicating "all done".  By
  960.            default,    yyyyyyyytttteeeerrrrmmmmiiiinnnnaaaatttteeee(((()))) is also called when an end-of-
  961.            file is encountered.  It    is a macro and may be
  962.            redefined.
  963.  
  964.      TTTTHHHHEEEE GGGGEEEENNNNEEEERRRRAAAATTTTEEEEDDDD SSSSCCCCAAAANNNNNNNNEEEERRRR
  965.       The output of    _f_l_e_x is    the file lllleeeexxxx....yyyyyyyy....cccc,,,, which contains the
  966.       scanning routine yyyyyyyylllleeeexxxx(((()))),,,, a number of    tables used by it for
  967.       matching tokens, and a number    of auxiliary routines and
  968.       macros.  By default, yyyyyyyylllleeeexxxx(((()))) is declared as follows:
  969.  
  970.           int yylex()
  971.           {
  972.           ... various definitions and the actions in here ...
  973.           }
  974.  
  975.       (If your environment supports    function prototypes, then it
  976.       will be "int yylex( void )".)     This definition may be
  977.       changed by defining the "YY_DECL" macro.  For    example, you
  978.       could    use:
  979.  
  980.           #define YY_DECL float lexscan( a,    b ) float a, b;
  981.  
  982.       to give the scanning routine the name    _l_e_x_s_c_a_n, returning a
  983.       float, and taking two    floats as arguments.  Note that    if you
  984.  
  985.  
  986.  
  987.      Page 15                         (printed 5/18/98)
  988.  
  989.  
  990.  
  991.  
  992.  
  993.  
  994.      FFFFLLLLEEEEXXXX((((1111))))         VVVVeeeerrrrssssiiiioooonnnn 2222....5555 ((((AAAApppprrrriiiillll 1111999999995555))))           FFFFLLLLEEEEXXXX((((1111))))
  995.  
  996.  
  997.  
  998.       give arguments to the    scanning routine using a K&R-
  999.       style/non-prototyped function    declaration, you must
  1000.       terminate the    definition with    a semi-colon (;).
  1001.  
  1002.       Whenever yyyyyyyylllleeeexxxx(((()))) is called, it scans tokens from the global
  1003.       input    file _y_y_i_n (which defaults to stdin).  It continues
  1004.       until    it either reaches an end-of-file (at which point it
  1005.       returns the value 0) or one of its actions executes a    _r_e_t_u_r_n
  1006.       statement.
  1007.  
  1008.       If the scanner reaches an end-of-file, subsequent calls are
  1009.       undefined unless either _y_y_i_n is pointed at a new input file
  1010.       (in which case scanning continues from that file), or
  1011.       yyyyyyyyrrrreeeessssttttaaaarrrrtttt(((()))) is called.  yyyyyyyyrrrreeeessssttttaaaarrrrtttt(((()))) takes one    argument, a
  1012.       FFFFIIIILLLLEEEE **** pointer (which    can be nil, if you've set up YYYYYYYY____IIIINNNNPPPPUUUUTTTT
  1013.       to scan from a source    other than _y_y_i_n), and initializes _y_y_i_n
  1014.       for scanning from that file.    Essentially there is no
  1015.       difference between just assigning _y_y_i_n to a new input    file
  1016.       or using yyyyyyyyrrrreeeessssttttaaaarrrrtttt(((()))) to do so; the latter is available for
  1017.       compatibility    with previous versions of _f_l_e_x,    and because it
  1018.       can be used to switch    input files in the middle of scanning.
  1019.       It can also be used to throw away the    current    input buffer,
  1020.       by calling it    with an    argument of _y_y_i_n; but better is    to use
  1021.       YYYYYYYY____FFFFLLLLUUUUSSSSHHHH____BBBBUUUUFFFFFFFFEEEERRRR (see above).    Note that yyyyyyyyrrrreeeessssttttaaaarrrrtttt(((()))) does _n_o_t
  1022.       reset    the start condition to IIIINNNNIIIITTTTIIIIAAAALLLL (see Start Conditions,
  1023.       below).
  1024.  
  1025.       If yyyyyyyylllleeeexxxx(((()))) stops scanning due    to executing a _r_e_t_u_r_n
  1026.       statement in one of the actions, the scanner may then    be
  1027.       called again and it will resume scanning where it left off.
  1028.  
  1029.       By default (and for purposes of efficiency), the scanner
  1030.       uses block-reads rather than simple _g_e_t_c() calls to read
  1031.       characters from _y_y_i_n.    The nature of how it gets its input
  1032.       can be controlled by defining    the YYYYYYYY____IIIINNNNPPPPUUUUTTTT macro.
  1033.       YY_INPUT's calling sequence is
  1034.       "YY_INPUT(buf,result,max_size)".  Its    action is to place up
  1035.       to _m_a_x__s_i_z_e characters in the    character array    _b_u_f and    return
  1036.       in the integer variable _r_e_s_u_l_t either    the number of
  1037.       characters read or the constant YY_NULL (0 on    Unix systems)
  1038.       to indicate EOF.  The    default    YY_INPUT reads from the    global
  1039.       file-pointer "yyin".
  1040.  
  1041.       A sample definition of YY_INPUT (in the definitions section
  1042.       of the input file):
  1043.  
  1044.           %{
  1045.           #define YY_INPUT(buf,result,max_size) \
  1046.           { \
  1047.           int c    = getchar(); \
  1048.           result = (c == EOF) ?    YY_NULL    : (buf[0] = c, 1); \
  1049.           }
  1050.  
  1051.  
  1052.  
  1053.      Page 16                         (printed 5/18/98)
  1054.  
  1055.  
  1056.  
  1057.  
  1058.  
  1059.  
  1060.      FFFFLLLLEEEEXXXX((((1111))))         VVVVeeeerrrrssssiiiioooonnnn 2222....5555 ((((AAAApppprrrriiiillll 1111999999995555))))           FFFFLLLLEEEEXXXX((((1111))))
  1061.  
  1062.  
  1063.  
  1064.           %}
  1065.  
  1066.       This definition will change the input    processing to occur
  1067.       one character    at a time.
  1068.  
  1069.       When the scanner receives an end-of-file indication from
  1070.       YY_INPUT, it then checks the yyyyyyyywwwwrrrraaaapppp(((())))    function.  If yyyyyyyywwwwrrrraaaapppp(((())))
  1071.       returns false    (zero),    then it    is assumed that    the function
  1072.       has gone ahead and set up _y_y_i_n to point to another input
  1073.       file,    and scanning continues.     If it returns true (non-
  1074.       zero), then the scanner terminates, returning    0 to its
  1075.       caller.  Note    that in    either case, the start condition
  1076.       remains unchanged; it    does _n_o_t revert    to IIIINNNNIIIITTTTIIIIAAAALLLL....
  1077.  
  1078.       If you do not    supply your own    version    of yyyyyyyywwwwrrrraaaapppp(((()))),,,, then you
  1079.       must either use %%%%ooooppppttttiiiioooonnnn nnnnooooyyyyyyyywwwwrrrraaaapppp (in which case the scanner
  1080.       behaves as though yyyyyyyywwwwrrrraaaapppp(((()))) returned 1), or you must link
  1081.       with ----llllffffllll to obtain the default version of the routine,
  1082.       which    always returns 1.
  1083.  
  1084.       Three    routines are available for scanning from in-memory
  1085.       buffers rather than files:  yyyyyyyy____ssssccccaaaannnn____ssssttttrrrriiiinnnngggg(((()))),,,,
  1086.       yyyyyyyy____ssssccccaaaannnn____bbbbyyyytttteeeessss(((()))),,,, and yyyyyyyy____ssssccccaaaannnn____bbbbuuuuffffffffeeeerrrr(((()))).... See the discussion of
  1087.       them below in    the section Multiple Input Buffers.
  1088.  
  1089.       The scanner writes its EEEECCCCHHHHOOOO output to    the _y_y_o_u_t global
  1090.       (default, stdout), which may be redefined by the user    simply
  1091.       by assigning it to some other    FFFFIIIILLLLEEEE pointer.
  1092.  
  1093.      SSSSTTTTAAAARRRRTTTT CCCCOOOONNNNDDDDIIIITTTTIIIIOOOONNNNSSSS
  1094.       _f_l_e_x provides    a mechanism for    conditionally activating
  1095.       rules.  Any rule whose pattern is prefixed with "<sc>" will
  1096.       only be active when the scanner is in    the start condition
  1097.       named    "sc".  For example,
  1098.  
  1099.           <STRING>[^"]*       { /*    eat up the string body ... */
  1100.               ...
  1101.               }
  1102.  
  1103.       will be active only when the scanner is in the "STRING"
  1104.       start    condition, and
  1105.  
  1106.           <INITIAL,STRING,QUOTE>\.          {    /* handle an escape ...    */
  1107.               ...
  1108.               }
  1109.  
  1110.       will be active only when the current start condition is
  1111.       either "INITIAL", "STRING", or "QUOTE".
  1112.  
  1113.       Start    conditions are declared    in the definitions (first)
  1114.       section of the input using unindented    lines beginning    with
  1115.       either %%%%ssss or %%%%xxxx followed by a    list of    names.    The former
  1116.  
  1117.  
  1118.  
  1119.      Page 17                         (printed 5/18/98)
  1120.  
  1121.  
  1122.  
  1123.  
  1124.  
  1125.  
  1126.      FFFFLLLLEEEEXXXX((((1111))))         VVVVeeeerrrrssssiiiioooonnnn 2222....5555 ((((AAAApppprrrriiiillll 1111999999995555))))           FFFFLLLLEEEEXXXX((((1111))))
  1127.  
  1128.  
  1129.  
  1130.       declares _i_n_c_l_u_s_i_v_e start conditions, the latter _e_x_c_l_u_s_i_v_e
  1131.       start    conditions.  A start condition is activated using the
  1132.       BBBBEEEEGGGGIIIINNNN    action.     Until the next    BBBBEEEEGGGGIIIINNNN action is    executed,
  1133.       rules    with the given start condition will be active and
  1134.       rules    with other start conditions will be inactive.  If the
  1135.       start    condition is _i_n_c_l_u_s_i_v_e,    then rules with    no start
  1136.       conditions at    all will also be active.  If it    is _e_x_c_l_u_s_i_v_e,
  1137.       then _o_n_l_y rules qualified with the start condition will be
  1138.       active.  A set of rules contingent on    the same exclusive
  1139.       start    condition describe a scanner which is independent of
  1140.       any of the other rules in the    _f_l_e_x input.  Because of    this,
  1141.       exclusive start conditions make it easy to specify "mini-
  1142.       scanners" which scan portions    of the input that are
  1143.       syntactically    different from the rest    (e.g., comments).
  1144.  
  1145.       If the distinction between inclusive and exclusive start
  1146.       conditions is    still a    little vague, here's a simple example
  1147.       illustrating the connection between the two.    The set    of
  1148.       rules:
  1149.  
  1150.           %s example
  1151.           %%
  1152.  
  1153.           <example>foo   do_something();
  1154.  
  1155.           bar         something_else();
  1156.  
  1157.       is equivalent    to
  1158.  
  1159.           %x example
  1160.           %%
  1161.  
  1162.           <example>foo   do_something();
  1163.  
  1164.           <INITIAL,example>bar    something_else();
  1165.  
  1166.       Without the <<<<IIIINNNNIIIITTTTIIIIAAAALLLL,,,,eeeexxxxaaaammmmpppplllleeee>>>>    qualifier, the _b_a_r pattern in
  1167.       the second example wouldn't be active    (i.e., couldn't    match)
  1168.       when in start    condition eeeexxxxaaaammmmpppplllleeee.... If we just used <<<<eeeexxxxaaaammmmpppplllleeee>>>>
  1169.       to qualify _b_a_r, though, then it would    only be    active in
  1170.       eeeexxxxaaaammmmpppplllleeee and not in IIIINNNNIIIITTTTIIIIAAAALLLL,,,, while in the first example it's
  1171.       active in both, because in the first example the eeeexxxxaaaammmmpppplllleeee
  1172.       startion condition is    an _i_n_c_l_u_s_i_v_e ((((%%%%ssss)))) start    condition.
  1173.  
  1174.       Also note that the special start-condition specifier <<<<****>>>>
  1175.       matches every    start condition.  Thus,    the above example
  1176.       could    also have been written;
  1177.  
  1178.           %x example
  1179.           %%
  1180.  
  1181.           <example>foo   do_something();
  1182.  
  1183.  
  1184.  
  1185.      Page 18                         (printed 5/18/98)
  1186.  
  1187.  
  1188.  
  1189.  
  1190.  
  1191.  
  1192.      FFFFLLLLEEEEXXXX((((1111))))         VVVVeeeerrrrssssiiiioooonnnn 2222....5555 ((((AAAApppprrrriiiillll 1111999999995555))))           FFFFLLLLEEEEXXXX((((1111))))
  1193.  
  1194.  
  1195.  
  1196.           <*>bar    something_else();
  1197.  
  1198.  
  1199.       The default rule (to EEEECCCCHHHHOOOO any    unmatched character) remains
  1200.       active in start conditions.  It is equivalent    to:
  1201.  
  1202.           <*>.|\n      ECHO;
  1203.  
  1204.  
  1205.       BBBBEEEEGGGGIIIINNNN((((0000)))) returns to the original state where only the    rules
  1206.       with no start    conditions are active.    This state can also be
  1207.       referred to as the start-condition "INITIAL",    so
  1208.       BBBBEEEEGGGGIIIINNNN((((IIIINNNNIIIITTTTIIIIAAAALLLL)))) is equivalent to BBBBEEEEGGGGIIIINNNN((((0000)))).... (The parentheses
  1209.       around the start condition name are not required but are
  1210.       considered good style.)
  1211.  
  1212.       BBBBEEEEGGGGIIIINNNN    actions    can also be given as indented code at the
  1213.       beginning of the rules section.  For example,    the following
  1214.       will cause the scanner to enter the "SPECIAL"    start
  1215.       condition whenever yyyyyyyylllleeeexxxx(((()))) is    called and the global variable
  1216.       _e_n_t_e_r__s_p_e_c_i_a_l    is true:
  1217.  
  1218.               int enter_special;
  1219.  
  1220.           %x SPECIAL
  1221.           %%
  1222.               if ( enter_special )
  1223.               BEGIN(SPECIAL);
  1224.  
  1225.           <SPECIAL>blahblahblah
  1226.           ...more rules follow...
  1227.  
  1228.  
  1229.       To illustrate    the uses of start conditions, here is a
  1230.       scanner which    provides two different interpretations of a
  1231.       string like "123.456".  By default it    will treat it as three
  1232.       tokens, the integer "123", a dot ('.'), and the integer
  1233.       "456".  But if the string is preceded    earlier    in the line by
  1234.       the string "expect-floats" it    will treat it as a single
  1235.       token, the floating-point number 123.456:
  1236.  
  1237.           %{
  1238.           #include <math.h>
  1239.           %}
  1240.           %s expect
  1241.  
  1242.           %%
  1243.           expect-floats       BEGIN(expect);
  1244.  
  1245.           <expect>[0-9]+"."[0-9]+       {
  1246.               printf( "found a float, = %f\n",
  1247.                   atof(    yytext ) );
  1248.  
  1249.  
  1250.  
  1251.      Page 19                         (printed 5/18/98)
  1252.  
  1253.  
  1254.  
  1255.  
  1256.  
  1257.  
  1258.      FFFFLLLLEEEEXXXX((((1111))))         VVVVeeeerrrrssssiiiioooonnnn 2222....5555 ((((AAAApppprrrriiiillll 1111999999995555))))           FFFFLLLLEEEEXXXX((((1111))))
  1259.  
  1260.  
  1261.  
  1262.               }
  1263.           <expect>\n       {
  1264.               /* that's the    end of the line, so
  1265.                * we    need another "expect-number"
  1266.                * before we'll recognize any    more
  1267.                * numbers
  1268.                */
  1269.               BEGIN(INITIAL);
  1270.               }
  1271.  
  1272.           [0-9]+      {
  1273.               printf( "found an integer, = %d\n",
  1274.                   atoi(    yytext ) );
  1275.               }
  1276.  
  1277.           "."      printf( "found a dot\n" );
  1278.  
  1279.       Here is a scanner which recognizes (and discards) C comments
  1280.       while    maintaining a count of the current input line.
  1281.  
  1282.           %x comment
  1283.           %%
  1284.               int line_num = 1;
  1285.  
  1286.           "/*"       BEGIN(comment);
  1287.  
  1288.           <comment>[^*\n]*          /* eat anything that's not a '*' */
  1289.           <comment>"*"+[^*/\n]*   /* eat up    '*'s not followed by '/'s */
  1290.           <comment>\n          ++line_num;
  1291.           <comment>"*"+"/"          BEGIN(INITIAL);
  1292.  
  1293.       This scanner goes to a bit of    trouble    to match as much text
  1294.       as possible with each    rule.  In general, when    attempting to
  1295.       write    a high-speed scanner try to match as much possible in
  1296.       each rule, as    it's a big win.
  1297.  
  1298.       Note that start-conditions names are really integer values
  1299.       and can be stored as such.  Thus, the    above could be
  1300.       extended in the following fashion:
  1301.  
  1302.           %x comment foo
  1303.           %%
  1304.               int line_num = 1;
  1305.               int comment_caller;
  1306.  
  1307.           "/*"       {
  1308.                comment_caller = INITIAL;
  1309.                BEGIN(comment);
  1310.                }
  1311.  
  1312.           ...
  1313.  
  1314.  
  1315.  
  1316.  
  1317.      Page 20                         (printed 5/18/98)
  1318.  
  1319.  
  1320.  
  1321.  
  1322.  
  1323.  
  1324.      FFFFLLLLEEEEXXXX((((1111))))         VVVVeeeerrrrssssiiiioooonnnn 2222....5555 ((((AAAApppprrrriiiillll 1111999999995555))))           FFFFLLLLEEEEXXXX((((1111))))
  1325.  
  1326.  
  1327.  
  1328.           <foo>"/*"       {
  1329.                comment_caller = foo;
  1330.                BEGIN(comment);
  1331.                }
  1332.  
  1333.           <comment>[^*\n]*          /* eat anything that's not a '*' */
  1334.           <comment>"*"+[^*/\n]*   /* eat up    '*'s not followed by '/'s */
  1335.           <comment>\n          ++line_num;
  1336.           <comment>"*"+"/"          BEGIN(comment_caller);
  1337.  
  1338.       Furthermore, you can access the current start    condition
  1339.       using    the integer-valued YYYYYYYY____SSSSTTTTAAAARRRRTTTT macro.  For    example, the
  1340.       above    assignments to _c_o_m_m_e_n_t__c_a_l_l_e_r could instead be written
  1341.  
  1342.           comment_caller = YY_START;
  1343.  
  1344.       Flex provides    YYYYYYYYSSSSTTTTAAAATTTTEEEE    as an alias for    YYYYYYYY____SSSSTTTTAAAARRRRTTTT (since    that
  1345.       is what's used by AT&T _l_e_x).
  1346.  
  1347.       Note that start conditions do    not have their own name-space;
  1348.       %s's and %x's    declare    names in the same fashion as
  1349.       #define's.
  1350.  
  1351.       Finally, here's an example of    how to match C-style quoted
  1352.       strings using    exclusive start    conditions, including expanded
  1353.       escape sequences (but    not including checking for a string
  1354.       that's too long):
  1355.  
  1356.           %x str
  1357.  
  1358.           %%
  1359.               char string_buf[MAX_STR_CONST];
  1360.               char *string_buf_ptr;
  1361.  
  1362.  
  1363.           \"      string_buf_ptr = string_buf; BEGIN(str);
  1364.  
  1365.           <str>\"         { /* saw closing quote - all done */
  1366.               BEGIN(INITIAL);
  1367.               *string_buf_ptr =    '\0';
  1368.               /* return    string constant    token type and
  1369.                * value to parser
  1370.                */
  1371.               }
  1372.  
  1373.           <str>\n         {
  1374.               /* error - unterminated string constant */
  1375.               /* generate error    message    */
  1376.               }
  1377.  
  1378.           <str>\\[0-7]{1,3}    {
  1379.               /* octal escape sequence */
  1380.  
  1381.  
  1382.  
  1383.      Page 21                         (printed 5/18/98)
  1384.  
  1385.  
  1386.  
  1387.  
  1388.  
  1389.  
  1390.      FFFFLLLLEEEEXXXX((((1111))))         VVVVeeeerrrrssssiiiioooonnnn 2222....5555 ((((AAAApppprrrriiiillll 1111999999995555))))           FFFFLLLLEEEEXXXX((((1111))))
  1391.  
  1392.  
  1393.  
  1394.               int result;
  1395.  
  1396.               (void) sscanf( yytext + 1, "%o", &result );
  1397.  
  1398.               if ( result > 0xff )
  1399.                   /* error,    constant is out-of-bounds */
  1400.  
  1401.               *string_buf_ptr++    = result;
  1402.               }
  1403.  
  1404.           <str>\\[0-9]+ {
  1405.               /* generate error    - bad escape sequence; something
  1406.                * like '\48' or '\0777777'
  1407.                */
  1408.               }
  1409.  
  1410.           <str>\\n    *string_buf_ptr++ = '\n';
  1411.           <str>\\t    *string_buf_ptr++ = '\t';
  1412.           <str>\\r    *string_buf_ptr++ = '\r';
  1413.           <str>\\b    *string_buf_ptr++ = '\b';
  1414.           <str>\\f    *string_buf_ptr++ = '\f';
  1415.  
  1416.           <str>\\(.|\n)  *string_buf_ptr++ = yytext[1];
  1417.  
  1418.           <str>[^\\\n\"]+         {
  1419.               char *yptr = yytext;
  1420.  
  1421.               while ( *yptr )
  1422.                   *string_buf_ptr++    = *yptr++;
  1423.               }
  1424.  
  1425.  
  1426.       Often, such as in some of the    examples above,    you wind up
  1427.       writing a whole bunch    of rules all preceded by the same
  1428.       start    condition(s).  Flex makes this a little    easier and
  1429.       cleaner by introducing a notion of start condition _s_c_o_p_e. A
  1430.       start    condition scope    is begun with:
  1431.  
  1432.           <SCs>{
  1433.  
  1434.       where    _S_C_s is a list of one or    more start conditions.    Inside
  1435.       the start condition scope, every rule    automatically has the
  1436.       prefix <_S_C_s> applied to it, until a '}' which    matches    the
  1437.       initial '{'. So, for example,
  1438.  
  1439.           <ESC>{
  1440.           "\\n"      return '\n';
  1441.           "\\r"      return '\r';
  1442.           "\\f"      return '\f';
  1443.           "\\0"      return '\0';
  1444.           }
  1445.  
  1446.  
  1447.  
  1448.  
  1449.      Page 22                         (printed 5/18/98)
  1450.  
  1451.  
  1452.  
  1453.  
  1454.  
  1455.  
  1456.      FFFFLLLLEEEEXXXX((((1111))))         VVVVeeeerrrrssssiiiioooonnnn 2222....5555 ((((AAAApppprrrriiiillll 1111999999995555))))           FFFFLLLLEEEEXXXX((((1111))))
  1457.  
  1458.  
  1459.  
  1460.       is equivalent    to:
  1461.  
  1462.           <ESC>"\\n"  return '\n';
  1463.           <ESC>"\\r"  return '\r';
  1464.           <ESC>"\\f"  return '\f';
  1465.           <ESC>"\\0"  return '\0';
  1466.  
  1467.       Start    condition scopes may be    nested.
  1468.  
  1469.       Three    routines are available for manipulating    stacks of
  1470.       start    conditions:
  1471.  
  1472.       vvvvooooiiiidddd yyyyyyyy____ppppuuuusssshhhh____ssssttttaaaatttteeee((((iiiinnnntttt nnnneeeewwww____ssssttttaaaatttteeee))))
  1473.            pushes the current start    condition onto the top of the
  1474.            start condition stack and switches to _n_e_w__s_t_a_t_e as
  1475.            though you had used BBBBEEEEGGGGIIIINNNN nnnneeeewwww____ssssttttaaaatttteeee (recall that    start
  1476.            condition names are also    integers).
  1477.  
  1478.       vvvvooooiiiidddd yyyyyyyy____ppppoooopppp____ssssttttaaaatttteeee(((())))
  1479.            pops the    top of the stack and switches to it via    BBBBEEEEGGGGIIIINNNN....
  1480.  
  1481.       iiiinnnntttt yyyyyyyy____ttttoooopppp____ssssttttaaaatttteeee(((())))
  1482.            returns the top of the stack without altering the
  1483.            stack's contents.
  1484.  
  1485.       The start condition stack grows dynamically and so has no
  1486.       built-in size    limitation.  If    memory is exhausted, program
  1487.       execution aborts.
  1488.  
  1489.       To use start condition stacks, your scanner must include a
  1490.       %%%%ooooppppttttiiiioooonnnn ssssttttaaaacccckkkk    directive (see Options below).
  1491.  
  1492.      MMMMUUUULLLLTTTTIIIIPPPPLLLLEEEE IIIINNNNPPPPUUUUTTTT BBBBUUUUFFFFFFFFEEEERRRRSSSS
  1493.       Some scanners    (such as those which support "include" files)
  1494.       require reading from several input streams.  As _f_l_e_x
  1495.       scanners do a    large amount of    buffering, one cannot control
  1496.       where    the next input will be read from by simply writing a
  1497.       YYYYYYYY____IIIINNNNPPPPUUUUTTTT which is sensitive to the scanning context.
  1498.       YYYYYYYY____IIIINNNNPPPPUUUUTTTT is only called when the scanner reaches the end of
  1499.       its buffer, which may    be a long time after scanning a
  1500.       statement such as an "include" which requires    switching the
  1501.       input    source.
  1502.  
  1503.       To negotiate these sorts of problems,    _f_l_e_x provides a
  1504.       mechanism for    creating and switching between multiple    input
  1505.       buffers.  An input buffer is created by using:
  1506.  
  1507.           YY_BUFFER_STATE yy_create_buffer(    FILE *file, int    size )
  1508.  
  1509.       which    takes a    _F_I_L_E pointer and a size    and creates a buffer
  1510.       associated with the given file and large enough to hold _s_i_z_e
  1511.       characters (when in doubt, use YYYYYYYY____BBBBUUUUFFFF____SSSSIIIIZZZZEEEE for the size).
  1512.  
  1513.  
  1514.  
  1515.      Page 23                         (printed 5/18/98)
  1516.  
  1517.  
  1518.  
  1519.  
  1520.  
  1521.  
  1522.      FFFFLLLLEEEEXXXX((((1111))))         VVVVeeeerrrrssssiiiioooonnnn 2222....5555 ((((AAAApppprrrriiiillll 1111999999995555))))           FFFFLLLLEEEEXXXX((((1111))))
  1523.  
  1524.  
  1525.  
  1526.       It returns a YYYYYYYY____BBBBUUUUFFFFFFFFEEEERRRR____SSSSTTTTAAAATTTTEEEE handle, which may then be
  1527.       passed to other routines (see    below).     The YYYYYYYY____BBBBUUUUFFFFFFFFEEEERRRR____SSSSTTTTAAAATTTTEEEE
  1528.       type is a pointer to an opaque ssssttttrrrruuuucccctttt    yyyyyyyy____bbbbuuuuffffffffeeeerrrr____ssssttttaaaatttteeee
  1529.       structure, so    you may    safely initialize YY_BUFFER_STATE
  1530.       variables to ((((((((YYYYYYYY____BBBBUUUUFFFFFFFFEEEERRRR____SSSSTTTTAAAATTTTEEEE)))) 0000)))) if    you wish, and also
  1531.       refer    to the opaque structure    in order to correctly declare
  1532.       input    buffers    in source files    other than that    of your
  1533.       scanner.  Note that the _F_I_L_E pointer in the call to
  1534.       yyyyyyyy____ccccrrrreeeeaaaatttteeee____bbbbuuuuffffffffeeeerrrr is only used    as the value of    _y_y_i_n seen by
  1535.       YYYYYYYY____IIIINNNNPPPPUUUUTTTT;;;; if you redefine YYYYYYYY____IIIINNNNPPPPUUUUTTTT so    it no longer uses
  1536.       _y_y_i_n,    then you can safely pass a nil _F_I_L_E pointer to
  1537.       yyyyyyyy____ccccrrrreeeeaaaatttteeee____bbbbuuuuffffffffeeeerrrr.... You    select a particular buffer to scan
  1538.       from using:
  1539.  
  1540.           void yy_switch_to_buffer(    YY_BUFFER_STATE    new_buffer )
  1541.  
  1542.       switches the scanner's input buffer so subsequent tokens
  1543.       will come from _n_e_w__b_u_f_f_e_r. Note that yyyyyyyy____sssswwwwiiiittttcccchhhh____ttttoooo____bbbbuuuuffffffffeeeerrrr(((())))
  1544.       may be used by yywrap() to set things    up for continued
  1545.       scanning, instead of opening a new file and pointing _y_y_i_n at
  1546.       it.  Note also that switching    input sources via either
  1547.       yyyyyyyy____sssswwwwiiiittttcccchhhh____ttttoooo____bbbbuuuuffffffffeeeerrrr(((())))    or yyyyyyyywwwwrrrraaaapppp(((()))) does _n_o_t change the    start
  1548.       condition.
  1549.  
  1550.           void yy_delete_buffer( YY_BUFFER_STATE buffer )
  1551.  
  1552.       is used to reclaim the storage associated with a buffer.  (
  1553.       bbbbuuuuffffffffeeeerrrr can be    nil, in    which case the routine does nothing.)
  1554.       You can also clear the current contents of a buffer using:
  1555.  
  1556.           void yy_flush_buffer( YY_BUFFER_STATE buffer )
  1557.  
  1558.       This function    discards the buffer's contents,    so the next
  1559.       time the scanner attempts to match a token from the buffer,
  1560.       it will first    fill the buffer    anew using YYYYYYYY____IIIINNNNPPPPUUUUTTTT....
  1561.  
  1562.       yyyyyyyy____nnnneeeewwww____bbbbuuuuffffffffeeeerrrr(((()))) is an    alias for yyyyyyyy____ccccrrrreeeeaaaatttteeee____bbbbuuuuffffffffeeeerrrr(((()))),,,, provided
  1563.       for compatibility with the C++ use of    _n_e_w and    _d_e_l_e_t_e for
  1564.       creating and destroying dynamic objects.
  1565.  
  1566.       Finally, the YYYYYYYY____CCCCUUUURRRRRRRREEEENNNNTTTT____BBBBUUUUFFFFFFFFEEEERRRR macro returns a
  1567.       YYYYYYYY____BBBBUUUUFFFFFFFFEEEERRRR____SSSSTTTTAAAATTTTEEEE handle to the    current    buffer.
  1568.  
  1569.       Here is an example of    using these features for writing a
  1570.       scanner which    expands    include    files (the <<<<<<<<EEEEOOOOFFFF>>>>>>>> feature is
  1571.       discussed below):
  1572.  
  1573.           /* the "incl" state is used for picking up the name
  1574.            * of an include file
  1575.            */
  1576.           %x incl
  1577.  
  1578.  
  1579.  
  1580.  
  1581.      Page 24                         (printed 5/18/98)
  1582.  
  1583.  
  1584.  
  1585.  
  1586.  
  1587.  
  1588.      FFFFLLLLEEEEXXXX((((1111))))         VVVVeeeerrrrssssiiiioooonnnn 2222....5555 ((((AAAApppprrrriiiillll 1111999999995555))))           FFFFLLLLEEEEXXXX((((1111))))
  1589.  
  1590.  
  1591.  
  1592.           %{
  1593.           #define MAX_INCLUDE_DEPTH    10
  1594.           YY_BUFFER_STATE include_stack[MAX_INCLUDE_DEPTH];
  1595.           int include_stack_ptr = 0;
  1596.           %}
  1597.  
  1598.           %%
  1599.           include          BEGIN(incl);
  1600.  
  1601.           [a-z]+          ECHO;
  1602.           [^a-z\n]*\n?      ECHO;
  1603.  
  1604.           <incl>[ \t]*    /* eat the whitespace */
  1605.           <incl>[^ \t\n]+    { /* got the include file name */
  1606.               if ( include_stack_ptr >=    MAX_INCLUDE_DEPTH )
  1607.               {
  1608.               fprintf( stderr, "Includes nested too    deeply"    );
  1609.               exit(    1 );
  1610.               }
  1611.  
  1612.               include_stack[include_stack_ptr++] =
  1613.               YY_CURRENT_BUFFER;
  1614.  
  1615.               yyin = fopen( yytext, "r"    );
  1616.  
  1617.               if ( ! yyin )
  1618.               error( ... );
  1619.  
  1620.               yy_switch_to_buffer(
  1621.               yy_create_buffer( yyin, YY_BUF_SIZE )    );
  1622.  
  1623.               BEGIN(INITIAL);
  1624.               }
  1625.  
  1626.           <<EOF>> {
  1627.               if ( --include_stack_ptr < 0 )
  1628.               {
  1629.               yyterminate();
  1630.               }
  1631.  
  1632.               else
  1633.               {
  1634.               yy_delete_buffer( YY_CURRENT_BUFFER );
  1635.               yy_switch_to_buffer(
  1636.                    include_stack[include_stack_ptr]    );
  1637.               }
  1638.               }
  1639.  
  1640.       Three    routines are available for setting up input buffers
  1641.       for scanning in-memory strings instead of files.  All    of
  1642.       them create a    new input buffer for scanning the string, and
  1643.       return a corresponding YYYYYYYY____BBBBUUUUFFFFFFFFEEEERRRR____SSSSTTTTAAAATTTTEEEE handle    (which you
  1644.  
  1645.  
  1646.  
  1647.      Page 25                         (printed 5/18/98)
  1648.  
  1649.  
  1650.  
  1651.  
  1652.  
  1653.  
  1654.      FFFFLLLLEEEEXXXX((((1111))))         VVVVeeeerrrrssssiiiioooonnnn 2222....5555 ((((AAAApppprrrriiiillll 1111999999995555))))           FFFFLLLLEEEEXXXX((((1111))))
  1655.  
  1656.  
  1657.  
  1658.       should delete    with yyyyyyyy____ddddeeeelllleeeetttteeee____bbbbuuuuffffffffeeeerrrr(((())))    when done with it).
  1659.       They also switch to the new buffer using
  1660.       yyyyyyyy____sssswwwwiiiittttcccchhhh____ttttoooo____bbbbuuuuffffffffeeeerrrr(((()))),,,, so the    next call to yyyyyyyylllleeeexxxx(((()))) will
  1661.       start    scanning the string.
  1662.  
  1663.       yyyyyyyy____ssssccccaaaannnn____ssssttttrrrriiiinnnngggg((((ccccoooonnnnsssstttt cccchhhhaaaarrrr ****ssssttttrrrr))))
  1664.            scans a NUL-terminated string.
  1665.  
  1666.       yyyyyyyy____ssssccccaaaannnn____bbbbyyyytttteeeessss((((ccccoooonnnnsssstttt cccchhhhaaaarrrr ****bbbbyyyytttteeeessss,,,, iiiinnnntttt lllleeeennnn))))
  1667.            scans _l_e_n bytes (including possibly NUL's) starting at
  1668.            location    _b_y_t_e_s.
  1669.  
  1670.       Note that both of these functions create and scan a _c_o_p_y of
  1671.       the string or    bytes.    (This may be desirable,    since yyyyyyyylllleeeexxxx(((())))
  1672.       modifies the contents    of the buffer it is scanning.)    You
  1673.       can avoid the    copy by    using:
  1674.  
  1675.       yyyyyyyy____ssssccccaaaannnn____bbbbuuuuffffffffeeeerrrr((((cccchhhhaaaarrrr ****bbbbaaaasssseeee,,,, yyyyyyyy____ssssiiiizzzzeeee____tttt ssssiiiizzzzeeee))))
  1676.            which scans in place the    buffer starting    at _b_a_s_e,
  1677.            consisting of _s_i_z_e bytes, the last two bytes of which
  1678.            _m_u_s_t be YYYYYYYY____EEEENNNNDDDD____OOOOFFFF____BBBBUUUUFFFFFFFFEEEERRRR____CCCCHHHHAAAARRRR (ASCII NUL).  These last
  1679.            two bytes are not scanned; thus,    scanning consists of
  1680.            bbbbaaaasssseeee[[[[0000]]]] through bbbbaaaasssseeee[[[[ssssiiiizzzzeeee----2222]]]],,,, inclusive.
  1681.  
  1682.            If you fail to set up _b_a_s_e in this manner (i.e.,    forget
  1683.            the final two YYYYYYYY____EEEENNNNDDDD____OOOOFFFF____BBBBUUUUFFFFFFFFEEEERRRR____CCCCHHHHAAAARRRR bytes), then
  1684.            yyyyyyyy____ssssccccaaaannnn____bbbbuuuuffffffffeeeerrrr(((())))    returns    a nil pointer instead of
  1685.            creating    a new input buffer.
  1686.  
  1687.            The type    yyyyyyyy____ssssiiiizzzzeeee____tttt is an    integral type to which you can
  1688.            cast an integer expression reflecting the size of the
  1689.            buffer.
  1690.  
  1691.      EEEENNNNDDDD----OOOOFFFF----FFFFIIIILLLLEEEE RRRRUUUULLLLEEEESSSS
  1692.       The special rule "<<EOF>>" indicates actions which are to be
  1693.       taken    when an    end-of-file is encountered and yywrap()
  1694.       returns non-zero (i.e., indicates no further files to
  1695.       process).  The action    must finish by doing one of four
  1696.       things:
  1697.  
  1698.       -    assigning _y_y_i_n to a new input file (in previous
  1699.            versions    of flex, after doing the assignment you    had to
  1700.            call the    special    action YYYYYYYY____NNNNEEEEWWWW____FFFFIIIILLLLEEEE;;;; this is no longer
  1701.            necessary);
  1702.  
  1703.       -    executing a _r_e_t_u_r_n statement;
  1704.  
  1705.       -    executing the special yyyyyyyytttteeeerrrrmmmmiiiinnnnaaaatttteeee(((()))) action;
  1706.  
  1707.       -    or, switching to    a new buffer using
  1708.            yyyyyyyy____sssswwwwiiiittttcccchhhh____ttttoooo____bbbbuuuuffffffffeeeerrrr(((()))) as    shown in the example above.
  1709.  
  1710.  
  1711.  
  1712.  
  1713.      Page 26                         (printed 5/18/98)
  1714.  
  1715.  
  1716.  
  1717.  
  1718.  
  1719.  
  1720.      FFFFLLLLEEEEXXXX((((1111))))         VVVVeeeerrrrssssiiiioooonnnn 2222....5555 ((((AAAApppprrrriiiillll 1111999999995555))))           FFFFLLLLEEEEXXXX((((1111))))
  1721.  
  1722.  
  1723.  
  1724.       <<EOF>> rules    may not    be used    with other patterns; they may
  1725.       only be qualified with a list    of start conditions.  If an
  1726.       unqualified <<EOF>> rule is given, it    applies    to _a_l_l start
  1727.       conditions which do not already have <<EOF>> actions.     To
  1728.       specify an <<EOF>> rule for only the initial start
  1729.       condition, use
  1730.  
  1731.           <INITIAL><<EOF>>
  1732.  
  1733.  
  1734.       These    rules are useful for catching things like unclosed
  1735.       comments.  An    example:
  1736.  
  1737.           %x quote
  1738.           %%
  1739.  
  1740.           ...other rules for dealing with quotes...
  1741.  
  1742.           <quote><<EOF>>   {
  1743.                error( "unterminated quote" );
  1744.                yyterminate();
  1745.                }
  1746.           <<EOF>>  {
  1747.                if ( *++filelist    )
  1748.                yyin    = fopen( *filelist, "r"    );
  1749.                else
  1750.               yyterminate();
  1751.                }
  1752.  
  1753.  
  1754.      MMMMIIIISSSSCCCCEEEELLLLLLLLAAAANNNNEEEEOOOOUUUUSSSS MMMMAAAACCCCRRRROOOOSSSS
  1755.       The macro YYYYYYYY____UUUUSSSSEEEERRRR____AAAACCCCTTTTIIIIOOOONNNN can be defined to provide an    action
  1756.       which    is always executed prior to the    matched    rule's action.
  1757.       For example, it could    be #define'd to    call a routine to
  1758.       convert yytext to lower-case.     When YYYYYYYY____UUUUSSSSEEEERRRR____AAAACCCCTTTTIIIIOOOONNNN is
  1759.       invoked, the variable    _y_y__a_c_t gives the number    of the matched
  1760.       rule (rules are numbered starting with 1).  Suppose you want
  1761.       to profile how often each of your rules is matched.  The
  1762.       following would do the trick:
  1763.  
  1764.           #define YY_USER_ACTION ++ctr[yy_act]
  1765.  
  1766.       where    _c_t_r is an array    to hold    the counts for the different
  1767.       rules.  Note that the    macro YYYYYYYY____NNNNUUUUMMMM____RRRRUUUULLLLEEEESSSS gives the total
  1768.       number of rules (including the default rule, even if you use
  1769.       ----ssss)))),,,, so a correct declaration    for _c_t_r    is:
  1770.  
  1771.           int ctr[YY_NUM_RULES];
  1772.  
  1773.  
  1774.       The macro YYYYYYYY____UUUUSSSSEEEERRRR____IIIINNNNIIIITTTT may be    defined    to provide an action
  1775.       which    is always executed before the first scan (and before
  1776.  
  1777.  
  1778.  
  1779.      Page 27                         (printed 5/18/98)
  1780.  
  1781.  
  1782.  
  1783.  
  1784.  
  1785.  
  1786.      FFFFLLLLEEEEXXXX((((1111))))         VVVVeeeerrrrssssiiiioooonnnn 2222....5555 ((((AAAApppprrrriiiillll 1111999999995555))))           FFFFLLLLEEEEXXXX((((1111))))
  1787.  
  1788.  
  1789.  
  1790.       the scanner's    internal initializations are done).  For
  1791.       example, it could be used to call a routine to read in a
  1792.       data table or    open a logging file.
  1793.  
  1794.       The macro yyyyyyyy____sssseeeetttt____iiiinnnntttteeeerrrraaaaccccttttiiiivvvveeee((((iiiissss____iiiinnnntttteeeerrrraaaaccccttttiiiivvvveeee)))) can be used to
  1795.       control whether the current buffer is    considered
  1796.       _i_n_t_e_r_a_c_t_i_v_e. An interactive buffer is    processed more slowly,
  1797.       but must be used when    the scanner's input source is indeed
  1798.       interactive to avoid problems    due to waiting to fill buffers
  1799.       (see the discussion of the ----IIII    flag below).  A    non-zero value
  1800.       in the macro invocation marks    the buffer as interactive, a
  1801.       zero value as    non-interactive.  Note that use    of this    macro
  1802.       overrides %%%%ooooppppttttiiiioooonnnn aaaallllwwwwaaaayyyyssss----iiiinnnntttteeeerrrraaaaccccttttiiiivvvveeee or %%%%ooooppppttttiiiioooonnnn nnnneeeevvvveeeerrrr----
  1803.       iiiinnnntttteeeerrrraaaaccccttttiiiivvvveeee (see Options below).  yyyyyyyy____sssseeeetttt____iiiinnnntttteeeerrrraaaaccccttttiiiivvvveeee(((()))) must
  1804.       be invoked prior to beginning    to scan    the buffer that    is (or
  1805.       is not) to be    considered interactive.
  1806.  
  1807.       The macro yyyyyyyy____sssseeeetttt____bbbboooollll((((aaaatttt____bbbboooollll)))) can be used to control whether
  1808.       the current buffer's scanning    context    for the    next token
  1809.       match    is done    as though at the beginning of a    line.  A non-
  1810.       zero macro argument makes rules anchored with
  1811.  
  1812.       The macro YYYYYYYY____AAAATTTT____BBBBOOOOLLLL(((())))    returns    true if    the next token scanned
  1813.       from the current buffer will have '^'    rules active, false
  1814.       otherwise.
  1815.  
  1816.       In the generated scanner, the    actions    are all    gathered in
  1817.       one large switch statement and separated using YYYYYYYY____BBBBRRRREEEEAAAAKKKK,,,,
  1818.       which    may be redefined.  By default, it is simply a "break",
  1819.       to separate each rule's action from the following rule's.
  1820.       Redefining YYYYYYYY____BBBBRRRREEEEAAAAKKKK allows, for example, C++ users to
  1821.       #define YY_BREAK to do nothing (while    being very careful
  1822.       that every rule ends with a "break" or a "return"!) to avoid
  1823.       suffering from unreachable statement warnings    where because
  1824.       a rule's action ends with "return", the YYYYYYYY____BBBBRRRREEEEAAAAKKKK is
  1825.       inaccessible.
  1826.  
  1827.      VVVVAAAALLLLUUUUEEEESSSS AAAAVVVVAAAAIIIILLLLAAAABBBBLLLLEEEE TTTTOOOO TTTTHHHHEEEE UUUUSSSSEEEERRRR
  1828.       This section summarizes the various values available to the
  1829.       user in the rule actions.
  1830.  
  1831.       -    cccchhhhaaaarrrr ****yyyyyyyytttteeeexxxxtttt holds the text of the current token.  It
  1832.            may be modified but not lengthened (you cannot append
  1833.            characters to the end).
  1834.  
  1835.            If the special directive    %%%%aaaarrrrrrrraaaayyyy appears in the first
  1836.            section of the scanner description, then    yyyyyyyytttteeeexxxxtttt is
  1837.            instead declared    cccchhhhaaaarrrr yyyyyyyytttteeeexxxxtttt[[[[YYYYYYYYLLLLMMMMAAAAXXXX]]]],,,, where YYYYYYYYLLLLMMMMAAAAXXXX is a
  1838.            macro definition    that you can redefine in the first
  1839.            section if you don't like the default value (generally
  1840.            8KB).  Using %%%%aaaarrrrrrrraaaayyyy results in somewhat slower
  1841.            scanners, but the value of yyyyyyyytttteeeexxxxtttt becomes immune    to
  1842.  
  1843.  
  1844.  
  1845.      Page 28                         (printed 5/18/98)
  1846.  
  1847.  
  1848.  
  1849.  
  1850.  
  1851.  
  1852.      FFFFLLLLEEEEXXXX((((1111))))         VVVVeeeerrrrssssiiiioooonnnn 2222....5555 ((((AAAApppprrrriiiillll 1111999999995555))))           FFFFLLLLEEEEXXXX((((1111))))
  1853.  
  1854.  
  1855.  
  1856.            calls to    _i_n_p_u_t()    and _u_n_p_u_t(), which potentially destroy
  1857.            its value when yyyyyyyytttteeeexxxxtttt is    a character pointer.  The
  1858.            opposite    of %%%%aaaarrrrrrrraaaayyyy is %%%%ppppooooiiiinnnntttteeeerrrr,,,, which is    the default.
  1859.  
  1860.            You cannot use %%%%aaaarrrrrrrraaaayyyy when generating C++ scanner
  1861.            classes (the ----++++ flag).
  1862.  
  1863.       -    iiiinnnntttt yyyyyyyylllleeeennnngggg holds    the length of the current token.
  1864.  
  1865.       -    FFFFIIIILLLLEEEE ****yyyyyyyyiiiinnnn is the file which by default _f_l_e_x reads
  1866.            from.  It may be    redefined but doing so only makes
  1867.            sense before scanning begins or after an    EOF has    been
  1868.            encountered.  Changing it in the    midst of scanning will
  1869.            have unexpected results since _f_l_e_x buffers its input;
  1870.            use yyyyyyyyrrrreeeessssttttaaaarrrrtttt(((()))) instead.     Once scanning terminates
  1871.            because an end-of-file has been seen, you can assign
  1872.            _y_y_i_n at the new input file and then call    the scanner
  1873.            again to    continue scanning.
  1874.  
  1875.       -    vvvvooooiiiidddd yyyyyyyyrrrreeeessssttttaaaarrrrtttt(((( FFFFIIIILLLLEEEE ****nnnneeeewwww____ffffiiiilllleeee ))))    may be called to point
  1876.            _y_y_i_n at the new input file.  The    switch-over to the new
  1877.            file is immediate (any previously buffered-up input is
  1878.            lost).  Note that calling yyyyyyyyrrrreeeessssttttaaaarrrrtttt(((()))) with _y_y_i_n as an
  1879.            argument    thus throws away the current input buffer and
  1880.            continues scanning the same input file.
  1881.  
  1882.       -    FFFFIIIILLLLEEEE ****yyyyyyyyoooouuuutttt is the file to which    EEEECCCCHHHHOOOO actions are done.
  1883.            It can be reassigned by the user.
  1884.  
  1885.       -    YYYYYYYY____CCCCUUUURRRRRRRREEEENNNNTTTT____BBBBUUUUFFFFFFFFEEEERRRR returns a YYYYYYYY____BBBBUUUUFFFFFFFFEEEERRRR____SSSSTTTTAAAATTTTEEEE handle to
  1886.            the current buffer.
  1887.  
  1888.       -    YYYYYYYY____SSSSTTTTAAAARRRRTTTT    returns    an integer value corresponding to the
  1889.            current start condition.     You can subsequently use this
  1890.            value with BBBBEEEEGGGGIIIINNNN    to return to that start    condition.
  1891.  
  1892.      IIIINNNNTTTTEEEERRRRFFFFAAAACCCCIIIINNNNGGGG WWWWIIIITTTTHHHH YYYYAAAACCCCCCCC
  1893.       One of the main uses of _f_l_e_x is as a companion to the    _y_a_c_c
  1894.       parser-generator.  _y_a_c_c parsers expect to call a routine
  1895.       named    yyyyyyyylllleeeexxxx(((())))    to find    the next input token.  The routine is
  1896.       supposed to return the type of the next token    as well    as
  1897.       putting any associated value in the global yyyyyyyyllllvvvvaaaallll.... To    use
  1898.       _f_l_e_x with _y_a_c_c, one specifies    the ----dddd option to _y_a_c_c to
  1899.       instruct it to generate the file yyyy....ttttaaaabbbb....hhhh containing
  1900.       definitions of all the %%%%ttttooookkkkeeeennnnssss appearing in the _y_a_c_c input.
  1901.       This file is then included in    the _f_l_e_x scanner.  For
  1902.       example, if one of the tokens    is "TOK_NUMBER", part of the
  1903.       scanner might    look like:
  1904.  
  1905.           %{
  1906.           #include "y.tab.h"
  1907.           %}
  1908.  
  1909.  
  1910.  
  1911.      Page 29                         (printed 5/18/98)
  1912.  
  1913.  
  1914.  
  1915.  
  1916.  
  1917.  
  1918.      FFFFLLLLEEEEXXXX((((1111))))         VVVVeeeerrrrssssiiiioooonnnn 2222....5555 ((((AAAApppprrrriiiillll 1111999999995555))))           FFFFLLLLEEEEXXXX((((1111))))
  1919.  
  1920.  
  1921.  
  1922.           %%
  1923.  
  1924.           [0-9]+        yylval = atoi( yytext ); return TOK_NUMBER;
  1925.  
  1926.  
  1927.      OOOOPPPPTTTTIIIIOOOONNNNSSSS
  1928.       _f_l_e_x has the following options:
  1929.  
  1930.       ----bbbb   Generate    backing-up information to _l_e_x._b_a_c_k_u_p. This is
  1931.            a list of scanner states    which require backing up and
  1932.            the input characters on which they do so.  By adding
  1933.            rules one can remove backing-up states.    If _a_l_l
  1934.            backing-up states are eliminated    and ----CCCCffff    or ----CCCCFFFF is
  1935.            used, the generated scanner will    run faster (see    the ----pppp
  1936.            flag).  Only users who wish to squeeze every last cycle
  1937.            out of their scanners need worry    about this option.
  1938.            (See the    section    on Performance Considerations below.)
  1939.  
  1940.       ----cccc   is a do-nothing,    deprecated option included for POSIX
  1941.            compliance.
  1942.  
  1943.       ----dddd   makes the generated scanner run in _d_e_b_u_g    mode.
  1944.            Whenever    a pattern is recognized    and the    global
  1945.            yyyyyyyy____fffflllleeeexxxx____ddddeeeebbbbuuuugggg is    non-zero (which    is the default), the
  1946.            scanner will write to _s_t_d_e_r_r a line of the form:
  1947.  
  1948.            --accepting rule at line 53 ("the matched text")
  1949.  
  1950.            The line    number refers to the location of the rule in
  1951.            the file    defining the scanner (i.e., the    file that was
  1952.            fed to flex).  Messages are also    generated when the
  1953.            scanner backs up, accepts the default rule, reaches the
  1954.            end of its input    buffer (or encounters a    NUL; at    this
  1955.            point, the two look the same as far as the scanner's
  1956.            concerned), or reaches an end-of-file.
  1957.  
  1958.       ----ffff   specifies _f_a_s_t _s_c_a_n_n_e_r. No table    compression is done
  1959.            and stdio is bypassed.  The result is large but fast.
  1960.            This option is equivalent to ----CCCCffffrrrr (see below).
  1961.  
  1962.       ----hhhh   generates a "help" summary of _f_l_e_x'_s options to _s_t_d_o_u_t
  1963.            and then    exits.    ----???? and --------hhhheeeellllpppp are synonyms for ----hhhh....
  1964.  
  1965.       ----iiii   instructs _f_l_e_x to generate a _c_a_s_e-_i_n_s_e_n_s_i_t_i_v_e scanner.
  1966.            The case    of letters given in the    _f_l_e_x input patterns
  1967.            will be ignored,    and tokens in the input    will be
  1968.            matched regardless of case.  The    matched    text given in
  1969.            _y_y_t_e_x_t will have    the preserved case (i.e., it will not
  1970.            be folded).
  1971.  
  1972.       ----llll   turns on    maximum    compatibility with the original    AT&T
  1973.            _l_e_x implementation.  Note that this does    not mean _f_u_l_l
  1974.  
  1975.  
  1976.  
  1977.      Page 30                         (printed 5/18/98)
  1978.  
  1979.  
  1980.  
  1981.  
  1982.  
  1983.  
  1984.      FFFFLLLLEEEEXXXX((((1111))))         VVVVeeeerrrrssssiiiioooonnnn 2222....5555 ((((AAAApppprrrriiiillll 1111999999995555))))           FFFFLLLLEEEEXXXX((((1111))))
  1985.  
  1986.  
  1987.  
  1988.            compatibility.  Use of this option costs    a considerable
  1989.            amount of performance, and it cannot be used with the
  1990.            ----++++,,,, ----ffff,,,, ----FFFF,,,, ----CCCCffff,,,,    or ----CCCCFFFF options.     For details on    the
  1991.            compatibilities it provides, see    the section
  1992.            "Incompatibilities With Lex And POSIX" below.  This
  1993.            option also results in the name YYYYYYYY____FFFFLLLLEEEEXXXX____LLLLEEEEXXXX____CCCCOOOOMMMMPPPPAAAATTTT
  1994.            being #define'd in the generated    scanner.
  1995.  
  1996.       ----nnnn   is another do-nothing, deprecated option    included only
  1997.            for POSIX compliance.
  1998.  
  1999.       ----pppp   generates a performance report to stderr.  The report
  2000.            consists    of comments regarding features of the _f_l_e_x
  2001.            input file which    will cause a serious loss of
  2002.            performance in the resulting scanner.  If you give the
  2003.            flag twice, you will also get comments regarding
  2004.            features    that lead to minor performance losses.
  2005.  
  2006.            Note that the use of RRRREEEEJJJJEEEECCCCTTTT,,,, %%%%ooooppppttttiiiioooonnnn yyyyyyyylllliiiinnnneeeennnnoooo,,,, and
  2007.            variable    trailing context (see the Deficiencies / Bugs
  2008.            section below) entails a    substantial performance
  2009.            penalty;    use of _y_y_m_o_r_e(), the ^^^^ operator, and the ----IIII
  2010.            flag entail minor performance penalties.
  2011.  
  2012.       ----ssss   causes the _d_e_f_a_u_l_t _r_u_l_e (that unmatched scanner input
  2013.            is echoed to _s_t_d_o_u_t) to be suppressed.  If the scanner
  2014.            encounters input    that does not match any    of its rules,
  2015.            it aborts with an error.     This option is    useful for
  2016.            finding holes in    a scanner's rule set.
  2017.  
  2018.       ----tttt   instructs _f_l_e_x to write the scanner it generates    to
  2019.            standard    output instead of lllleeeexxxx....yyyyyyyy....cccc....
  2020.  
  2021.       ----vvvv   specifies that _f_l_e_x should write    to _s_t_d_e_r_r a summary of
  2022.            statistics regarding the    scanner    it generates.  Most of
  2023.            the statistics are meaningless to the casual _f_l_e_x user,
  2024.            but the first line identifies the version of _f_l_e_x (same
  2025.            as reported by ----VVVV)))),,,, and the next    line the flags used
  2026.            when generating the scanner, including those that are
  2027.            on by default.
  2028.  
  2029.       ----wwww   suppresses warning messages.
  2030.  
  2031.       ----BBBB   instructs _f_l_e_x to generate a _b_a_t_c_h scanner, the
  2032.            opposite    of _i_n_t_e_r_a_c_t_i_v_e scanners    generated by ----IIII    (see
  2033.            below).    In general, you    use ----BBBB when you    are _c_e_r_t_a_i_n
  2034.            that your scanner will never be used interactively, and
  2035.            you want    to squeeze a _l_i_t_t_l_e more performance out of
  2036.            it.  If your goal is instead to squeeze out a _l_o_t more
  2037.            performance, you    should    be using the ----CCCCffff or ----CCCCFFFF
  2038.            options (discussed below), which    turn on    ----BBBB
  2039.            automatically anyway.
  2040.  
  2041.  
  2042.  
  2043.      Page 31                         (printed 5/18/98)
  2044.  
  2045.  
  2046.  
  2047.  
  2048.  
  2049.  
  2050.      FFFFLLLLEEEEXXXX((((1111))))         VVVVeeeerrrrssssiiiioooonnnn 2222....5555 ((((AAAApppprrrriiiillll 1111999999995555))))           FFFFLLLLEEEEXXXX((((1111))))
  2051.  
  2052.  
  2053.  
  2054.       ----FFFF   specifies that the _f_a_s_t scanner table representation
  2055.            should be used (and stdio bypassed).  This
  2056.            representation is about as fast as the full table
  2057.            representation ((((----ffff)))),,,, and    for some sets of patterns will
  2058.            be considerably smaller (and for    others,    larger).  In
  2059.            general,    if the pattern set contains both "keywords"
  2060.            and a catch-all,    "identifier" rule, such    as in the set:
  2061.  
  2062.            "case"    return TOK_CASE;
  2063.            "switch"  return TOK_SWITCH;
  2064.            ...
  2065.            "default" return TOK_DEFAULT;
  2066.            [a-z]+    return TOK_ID;
  2067.  
  2068.            then you're better off using the    full table
  2069.            representation.    If only    the "identifier" rule is
  2070.            present and you then use    a hash table or    some such to
  2071.            detect the keywords, you're better off using ----FFFF....
  2072.  
  2073.            This option is equivalent to ----CCCCFFFFrrrr (see below).  It
  2074.            cannot be used with ----++++....
  2075.  
  2076.       ----IIII   instructs _f_l_e_x to generate an _i_n_t_e_r_a_c_t_i_v_e scanner.  An
  2077.            interactive scanner is one that only looks ahead    to
  2078.            decide what token has been matched if it    absolutely
  2079.            must.  It turns out that    always looking one extra
  2080.            character ahead,    even if    the scanner has    already    seen
  2081.            enough text to disambiguate the current token, is a bit
  2082.            faster than only    looking    ahead when necessary.  But
  2083.            scanners    that always look ahead give dreadful
  2084.            interactive performance;    for example, when a user types
  2085.            a newline, it is    not recognized as a newline token
  2086.            until they enter    _a_n_o_t_h_e_r    token, which often means
  2087.            typing in another whole line.
  2088.  
  2089.            _F_l_e_x scanners default to    _i_n_t_e_r_a_c_t_i_v_e unless you use the
  2090.            ----CCCCffff or ----CCCCFFFF table-compression options (see below).
  2091.            That's because if you're    looking    for high-performance
  2092.            you should be using one of these    options, so if you
  2093.            didn't, _f_l_e_x assumes you'd rather trade off a bit of
  2094.            run-time    performance for    intuitive interactive
  2095.            behavior.  Note also that you _c_a_n_n_o_t use    ----IIII in
  2096.            conjunction with    ----CCCCffff or ----CCCCFFFF.... Thus, this option is not
  2097.            really needed; it is on by default for all those    cases
  2098.            in which    it is allowed.
  2099.  
  2100.            You can force a scanner to _n_o_t be interactive by    using
  2101.            ----BBBB (see above).
  2102.  
  2103.       ----LLLL   instructs _f_l_e_x not to generate ####lllliiiinnnneeee directives.
  2104.            Without this option, _f_l_e_x peppers the generated scanner
  2105.            with #line directives so    error messages in the actions
  2106.  
  2107.  
  2108.  
  2109.      Page 32                         (printed 5/18/98)
  2110.  
  2111.  
  2112.  
  2113.  
  2114.  
  2115.  
  2116.      FFFFLLLLEEEEXXXX((((1111))))         VVVVeeeerrrrssssiiiioooonnnn 2222....5555 ((((AAAApppprrrriiiillll 1111999999995555))))           FFFFLLLLEEEEXXXX((((1111))))
  2117.  
  2118.  
  2119.  
  2120.            will be correctly located with respect to either    the
  2121.            original    _f_l_e_x input file    (if the    errors are due to code
  2122.            in the input file), or lllleeeexxxx....yyyyyyyy....cccc (if the errors are
  2123.            _f_l_e_x'_s fault -- you should report these sorts of    errors
  2124.            to the email address given below).
  2125.  
  2126.       ----TTTT   makes _f_l_e_x run in _t_r_a_c_e mode.  It will generate a lot
  2127.            of messages to _s_t_d_e_r_r concerning    the form of the    input
  2128.            and the resultant non-deterministic and deterministic
  2129.            finite automata.     This option is    mostly for use in
  2130.            maintaining _f_l_e_x.
  2131.  
  2132.       ----VVVV   prints the version number to _s_t_d_o_u_t and exits.
  2133.            --------vvvveeeerrrrssssiiiioooonnnn is a synonym for ----VVVV....
  2134.  
  2135.       ----7777   instructs _f_l_e_x to generate a 7-bit scanner, i.e., one
  2136.            which can only recognized 7-bit characters in its
  2137.            input.  The advantage of    using ----7777 is that the scanner's
  2138.            tables can be up    to half    the size of those generated
  2139.            using the ----8888 option (see    below).     The disadvantage is
  2140.            that such scanners often    hang or    crash if their input
  2141.            contains    an 8-bit character.
  2142.  
  2143.            Note, however, that unless you generate your scanner
  2144.            using the ----CCCCffff or    ----CCCCFFFF table compression options, use of
  2145.            ----7777 will save only a small amount    of table space,    and
  2146.            make your scanner considerably less portable.  _F_l_e_x'_s
  2147.            default behavior    is to generate an 8-bit    scanner    unless
  2148.            you use the ----CCCCffff or ----CCCCFFFF,,,, in which    case _f_l_e_x defaults to
  2149.            generating 7-bit    scanners unless    your site was always
  2150.            configured to generate 8-bit scanners (as will often be
  2151.            the case    with non-USA sites).  You can tell whether
  2152.            flex generated a    7-bit or an 8-bit scanner by
  2153.            inspecting the flag summary in the ----vvvv output as
  2154.            described above.
  2155.  
  2156.            Note that if you    use ----CCCCffffeeee or ----CCCCFFFFeeee (those    table
  2157.            compression options, but    also using equivalence classes
  2158.            as discussed see    below),    flex still defaults to
  2159.            generating an 8-bit scanner, since usually with these
  2160.            compression options full    8-bit tables are not much more
  2161.            expensive than 7-bit tables.
  2162.  
  2163.       ----8888   instructs _f_l_e_x to generate an 8-bit scanner, i.e., one
  2164.            which can recognize 8-bit characters.  This flag    is
  2165.            only needed for scanners    generated using    ----CCCCffff or ----CCCCFFFF,,,, as
  2166.            otherwise flex defaults to generating an    8-bit scanner
  2167.            anyway.
  2168.  
  2169.            See the discussion of ----7777    above for flex's default
  2170.            behavior    and the    tradeoffs between 7-bit    and 8-bit
  2171.            scanners.
  2172.  
  2173.  
  2174.  
  2175.      Page 33                         (printed 5/18/98)
  2176.  
  2177.  
  2178.  
  2179.  
  2180.  
  2181.  
  2182.      FFFFLLLLEEEEXXXX((((1111))))         VVVVeeeerrrrssssiiiioooonnnn 2222....5555 ((((AAAApppprrrriiiillll 1111999999995555))))           FFFFLLLLEEEEXXXX((((1111))))
  2183.  
  2184.  
  2185.  
  2186.       ----++++   specifies that you want flex to generate    a C++ scanner
  2187.            class.  See the section on Generating C++ Scanners
  2188.            below for details.
  2189.  
  2190.       ----CCCC[[[[aaaaeeeeffffFFFFmmmmrrrr]]]]
  2191.            controls    the degree of table compression    and, more
  2192.            generally, trade-offs between small scanners and    fast
  2193.            scanners.
  2194.  
  2195.            ----CCCCaaaa ("align") instructs flex to trade off larger    tables
  2196.            in the generated    scanner    for faster performance because
  2197.            the elements of the tables are better aligned for
  2198.            memory access and computation.  On some RISC
  2199.            architectures, fetching and manipulating    longwords is
  2200.            more efficient than with    smaller-sized units such as
  2201.            shortwords.  This option    can double the size of the
  2202.            tables used by your scanner.
  2203.  
  2204.            ----CCCCeeee directs _f_l_e_x    to construct _e_q_u_i_v_a_l_e_n_c_e _c_l_a_s_s_e_s,
  2205.            i.e., sets of characters    which have identical lexical
  2206.            properties (for example,    if the only appearance of
  2207.            digits in the _f_l_e_x input    is in the character class
  2208.            "[0-9]" then the    digits '0', '1', ..., '9' will all be
  2209.            put in the same equivalence class).  Equivalence
  2210.            classes usually give dramatic reductions    in the final
  2211.            table/object file sizes (typically a factor of 2-5) and
  2212.            are pretty cheap    performance-wise (one array look-up
  2213.            per character scanned).
  2214.  
  2215.            ----CCCCffff specifies that the _f_u_l_l scanner tables should be
  2216.            generated - _f_l_e_x    should not compress the    tables by
  2217.            taking advantages of similar transition functions for
  2218.            different states.
  2219.  
  2220.            ----CCCCFFFF specifies that the alternate    fast scanner
  2221.            representation (described above under the ----FFFF flag)
  2222.            should be used.    This option cannot be used with    ----++++....
  2223.  
  2224.            ----CCCCmmmm directs _f_l_e_x    to construct _m_e_t_a-_e_q_u_i_v_a_l_e_n_c_e _c_l_a_s_s_e_s,
  2225.            which are sets of equivalence classes (or characters,
  2226.            if equivalence classes are not being used) that are
  2227.            commonly    used together.    Meta-equivalence classes are
  2228.            often a big win when using compressed tables, but they
  2229.            have a moderate performance impact (one or two "if"
  2230.            tests and one array look-up per character scanned).
  2231.  
  2232.            ----CCCCrrrr causes the generated    scanner    to _b_y_p_a_s_s use of the
  2233.            standard    I/O library (stdio) for    input.    Instead    of
  2234.            calling ffffrrrreeeeaaaadddd(((()))) or ggggeeeettttcccc(((()))),,,, the scanner will use the
  2235.            rrrreeeeaaaadddd(((()))) system call, resulting in    a performance gain
  2236.            which varies from system    to system, but in general is
  2237.            probably    negligible unless you are also using ----CCCCffff or
  2238.  
  2239.  
  2240.  
  2241.      Page 34                         (printed 5/18/98)
  2242.  
  2243.  
  2244.  
  2245.  
  2246.  
  2247.  
  2248.      FFFFLLLLEEEEXXXX((((1111))))         VVVVeeeerrrrssssiiiioooonnnn 2222....5555 ((((AAAApppprrrriiiillll 1111999999995555))))           FFFFLLLLEEEEXXXX((((1111))))
  2249.  
  2250.  
  2251.  
  2252.            ----CCCCFFFF.... Using ----CCCCrrrr can cause    strange    behavior if, for
  2253.            example,    you read from _y_y_i_n using stdio prior to
  2254.            calling the scanner (because the    scanner    will miss
  2255.            whatever    text your previous reads left in the stdio
  2256.            input buffer).
  2257.  
  2258.            ----CCCCrrrr has no effect if you    define YYYYYYYY____IIIINNNNPPPPUUUUTTTT    (see The
  2259.            Generated Scanner above).
  2260.  
  2261.            A lone ----CCCC specifies that    the scanner tables should be
  2262.            compressed but neither equivalence classes nor meta-
  2263.            equivalence classes should be used.
  2264.  
  2265.            The options ----CCCCffff or ----CCCCFFFF and ----CCCCmmmm do not make sense
  2266.            together    - there    is no opportunity for meta-equivalence
  2267.            classes if the table is not being compressed.
  2268.            Otherwise the options may be freely mixed, and are
  2269.            cumulative.
  2270.  
  2271.            The default setting is ----CCCCeeeemmmm,,,, which specifies that _f_l_e_x
  2272.            should generate equivalence classes and meta-
  2273.            equivalence classes.  This setting provides the highest
  2274.            degree of table compression.  You can trade off
  2275.            faster-executing    scanners at the    cost of    larger tables
  2276.            with the    following generally being true:
  2277.  
  2278.            slowest & smallest
  2279.              -Cem
  2280.              -Cm
  2281.              -Ce
  2282.              -C
  2283.              -C{f,F}e
  2284.              -C{f,F}
  2285.              -C{f,F}a
  2286.            fastest & largest
  2287.  
  2288.            Note that scanners with the smallest tables are usually
  2289.            generated and compiled the quickest, so during
  2290.            development you will usually want to use    the default,
  2291.            maximal compression.
  2292.  
  2293.            ----CCCCffffeeee is often a good compromise between speed and size
  2294.            for production scanners.
  2295.  
  2296.       ----oooooooouuuuttttppppuuuutttt
  2297.            directs flex to write the scanner to the    file oooouuuuttttppppuuuutttt
  2298.            instead of lllleeeexxxx....yyyyyyyy....cccc.... If you combine ----oooo with the ----tttt
  2299.            option, then the    scanner    is written to _s_t_d_o_u_t but its
  2300.            ####lllliiiinnnneeee directives    (see the ----LLLL option above) refer    to the
  2301.            file oooouuuuttttppppuuuutttt....
  2302.  
  2303.       ----PPPPpppprrrreeeeffffiiiixxxx
  2304.  
  2305.  
  2306.  
  2307.      Page 35                         (printed 5/18/98)
  2308.  
  2309.  
  2310.  
  2311.  
  2312.  
  2313.  
  2314.      FFFFLLLLEEEEXXXX((((1111))))         VVVVeeeerrrrssssiiiioooonnnn 2222....5555 ((((AAAApppprrrriiiillll 1111999999995555))))           FFFFLLLLEEEEXXXX((((1111))))
  2315.  
  2316.  
  2317.  
  2318.            changes the default _y_y prefix used by _f_l_e_x for all
  2319.            globally-visible    variable and function names to instead
  2320.            be _p_r_e_f_i_x. For example, ----PPPPffffoooooooo changes the name of
  2321.            yyyyyyyytttteeeexxxxtttt to ffffooooooootttteeeexxxxtttt.... It also changes the name of the
  2322.            default output file from    lllleeeexxxx....yyyyyyyy....cccc to lllleeeexxxx....ffffoooooooo....cccc.... Here
  2323.            are all of the names affected:
  2324.  
  2325.            yy_create_buffer
  2326.            yy_delete_buffer
  2327.            yy_flex_debug
  2328.            yy_init_buffer
  2329.            yy_flush_buffer
  2330.            yy_load_buffer_state
  2331.            yy_switch_to_buffer
  2332.            yyin
  2333.            yyleng
  2334.            yylex
  2335.            yylineno
  2336.            yyout
  2337.            yyrestart
  2338.            yytext
  2339.            yywrap
  2340.  
  2341.            (If you are using a C++ scanner,    then only yyyyyyyywwwwrrrraaaapppp and
  2342.            yyyyyyyyFFFFlllleeeexxxxLLLLeeeexxxxeeeerrrr are affected.)  Within your scanner itself,
  2343.            you can still refer to the global variables and
  2344.            functions using either version of their name; but
  2345.            externally, they    have the modified name.
  2346.  
  2347.            This option lets    you easily link    together multiple _f_l_e_x
  2348.            programs    into the same executable.  Note, though, that
  2349.            using this option also renames yyyyyyyywwwwrrrraaaapppp(((()))),,,,    so you now
  2350.            _m_u_s_t either provide your    own (appropriately-named)
  2351.            version of the routine for your scanner,    or use %%%%ooooppppttttiiiioooonnnn
  2352.            nnnnooooyyyyyyyywwwwrrrraaaapppp,,,, as linking with ----llllffffllll no longer    provides one
  2353.            for you by default.
  2354.  
  2355.       ----SSSSsssskkkkeeeelllleeeettttoooonnnn____ffffiiiilllleeee
  2356.            overrides the default skeleton file from    which _f_l_e_x
  2357.            constructs its scanners.     You'll    never need this    option
  2358.            unless you are doing _f_l_e_x maintenance or    development.
  2359.  
  2360.       _f_l_e_x also provides a mechanism for controlling options
  2361.       within the scanner specification itself, rather than from
  2362.       the flex command-line.  This is done by including %%%%ooooppppttttiiiioooonnnn
  2363.       directives in    the first section of the scanner
  2364.       specification.  You can specify multiple options with    a
  2365.       single %%%%ooooppppttttiiiioooonnnn directive, and    multiple directives in the
  2366.       first    section    of your    flex input file.
  2367.  
  2368.       Most options are given simply    as names, optionally preceded
  2369.       by the word "no" (with no intervening    whitespace) to negate
  2370.  
  2371.  
  2372.  
  2373.      Page 36                         (printed 5/18/98)
  2374.  
  2375.  
  2376.  
  2377.  
  2378.  
  2379.  
  2380.      FFFFLLLLEEEEXXXX((((1111))))         VVVVeeeerrrrssssiiiioooonnnn 2222....5555 ((((AAAApppprrrriiiillll 1111999999995555))))           FFFFLLLLEEEEXXXX((((1111))))
  2381.  
  2382.  
  2383.  
  2384.       their    meaning.  A number are equivalent to flex flags    or
  2385.       their    negation:
  2386.  
  2387.           7bit          -7 option
  2388.           8bit          -8 option
  2389.           align          -Ca option
  2390.           backup          -b option
  2391.           batch          -B option
  2392.           c++          -+ option
  2393.  
  2394.           caseful or
  2395.           case-sensitive  opposite of -i (default)
  2396.  
  2397.           case-insensitive or
  2398.           caseless          -i option
  2399.  
  2400.           debug          -d option
  2401.           default          opposite of -s option
  2402.           ecs          -Ce option
  2403.           fast          -F option
  2404.           full          -f option
  2405.           interactive     -I option
  2406.           lex-compat      -l option
  2407.           meta-ecs          -Cm option
  2408.           perf-report     -p option
  2409.           read          -Cr option
  2410.           stdout          -t option
  2411.           verbose          -v option
  2412.           warn          opposite of -w option
  2413.                   (use "%option nowarn" for    -w)
  2414.  
  2415.           array          equivalent to "%array"
  2416.           pointer          equivalent to "%pointer" (default)
  2417.  
  2418.       Some %%%%ooooppppttttiiiioooonnnn''''ssss provide features otherwise not    available:
  2419.  
  2420.       aaaallllwwwwaaaayyyyssss----iiiinnnntttteeeerrrraaaaccccttttiiiivvvveeee
  2421.            instructs flex to generate a scanner which always
  2422.            considers its input "interactive".  Normally, on    each
  2423.            new input file the scanner calls    iiiissssaaaattttttttyyyy(((()))) in an attempt
  2424.            to determine whether the    scanner's input    source is
  2425.            interactive and thus should be read a character at a
  2426.            time.  When this    option is used,    however, then no such
  2427.            call is made.
  2428.  
  2429.       mmmmaaaaiiiinnnn directs flex to provide a default mmmmaaaaiiiinnnn(((())))    program    for
  2430.            the scanner, which simply calls yyyyyyyylllleeeexxxx(((())))....    This option
  2431.            implies nnnnooooyyyyyyyywwwwrrrraaaapppp    (see below).
  2432.  
  2433.       nnnneeeevvvveeeerrrr----iiiinnnntttteeeerrrraaaaccccttttiiiivvvveeee
  2434.            instructs flex to generate a scanner which never
  2435.            considers its input "interactive" (again, no call made
  2436.  
  2437.  
  2438.  
  2439.      Page 37                         (printed 5/18/98)
  2440.  
  2441.  
  2442.  
  2443.  
  2444.  
  2445.  
  2446.      FFFFLLLLEEEEXXXX((((1111))))         VVVVeeeerrrrssssiiiioooonnnn 2222....5555 ((((AAAApppprrrriiiillll 1111999999995555))))           FFFFLLLLEEEEXXXX((((1111))))
  2447.  
  2448.  
  2449.  
  2450.            to iiiissssaaaattttttttyyyy(((()))))))).... This is the opposite of aaaallllwwwwaaaayyyyssss----
  2451.            iiiinnnntttteeeerrrraaaaccccttttiiiivvvveeee....
  2452.  
  2453.       ssssttttaaaacccckkkk
  2454.            enables the use of start    condition stacks (see Start
  2455.            Conditions above).
  2456.  
  2457.       ssssttttddddiiiinnnniiiitttt
  2458.            if set (i.e., %%%%ooooppppttttiiiioooonnnn ssssttttddddiiiinnnniiiitttt)))) initializes _y_y_i_n and
  2459.            _y_y_o_u_t to    _s_t_d_i_n and _s_t_d_o_u_t, instead of the default of
  2460.            _n_i_l. Some existing _l_e_x programs depend on this
  2461.            behavior, even though it    is not compliant with ANSI C,
  2462.            which does not require _s_t_d_i_n and    _s_t_d_o_u_t to be compile-
  2463.            time constant.
  2464.  
  2465.       yyyyyyyylllliiiinnnneeeennnnoooo
  2466.            directs _f_l_e_x to generate    a scanner that maintains the
  2467.            number of the current line read from its    input in the
  2468.            global variable yyyyyyyylllliiiinnnneeeennnnoooo.... This option is    implied    by
  2469.            %%%%ooooppppttttiiiioooonnnn lllleeeexxxx----ccccoooommmmppppaaaatttt....
  2470.  
  2471.       yyyyyyyywwwwrrrraaaapppp
  2472.            if unset    (i.e., %%%%ooooppppttttiiiioooonnnn nnnnooooyyyyyyyywwwwrrrraaaapppp)))),,,, makes    the scanner
  2473.            not call    yyyyyyyywwwwrrrraaaapppp(((()))) upon an end-of-file, but simply
  2474.            assume that there are no    more files to scan (until the
  2475.            user points _y_y_i_n    at a new file and calls    yyyyyyyylllleeeexxxx(((())))
  2476.            again).
  2477.  
  2478.       _f_l_e_x scans your rule actions to determine whether you    use
  2479.       the RRRREEEEJJJJEEEECCCCTTTT or    yyyyyyyymmmmoooorrrreeee(((()))) features.  The    rrrreeeejjjjeeeecccctttt and yyyyyyyymmmmoooorrrreeee
  2480.       options are available    to override its    decision as to whether
  2481.       you use the options, either by setting them (e.g., %%%%ooooppppttttiiiioooonnnn
  2482.       rrrreeeejjjjeeeecccctttt)))) to indicate the feature is indeed used, or unsetting
  2483.       them to indicate it actually is not used (e.g., %%%%ooooppppttttiiiioooonnnn
  2484.       nnnnooooyyyyyyyymmmmoooorrrreeee))))....
  2485.  
  2486.       Three    options    take string-delimited values, offset with '=':
  2487.  
  2488.           %option outfile="ABC"
  2489.  
  2490.       is equivalent    to ----ooooAAAABBBBCCCC,,,, and
  2491.  
  2492.           %option prefix="XYZ"
  2493.  
  2494.       is equivalent    to ----PPPPXXXXYYYYZZZZ.... Finally,
  2495.  
  2496.           %option yyclass="foo"
  2497.  
  2498.       only applies when generating a C++ scanner ( ----++++ option).  It
  2499.       informs _f_l_e_x that you    have derived ffffoooooooo as a subclass of
  2500.       yyyyyyyyFFFFlllleeeexxxxLLLLeeeexxxxeeeerrrr,,,, so _f_l_e_x will place your actions in the member
  2501.       function ffffoooooooo::::::::yyyyyyyylllleeeexxxx(((())))    instead    of yyyyyyyyFFFFlllleeeexxxxLLLLeeeexxxxeeeerrrr::::::::yyyyyyyylllleeeexxxx(((()))).... It
  2502.  
  2503.  
  2504.  
  2505.      Page 38                         (printed 5/18/98)
  2506.  
  2507.  
  2508.  
  2509.  
  2510.  
  2511.  
  2512.      FFFFLLLLEEEEXXXX((((1111))))         VVVVeeeerrrrssssiiiioooonnnn 2222....5555 ((((AAAApppprrrriiiillll 1111999999995555))))           FFFFLLLLEEEEXXXX((((1111))))
  2513.  
  2514.  
  2515.  
  2516.       also generates a yyyyyyyyFFFFlllleeeexxxxLLLLeeeexxxxeeeerrrr::::::::yyyyyyyylllleeeexxxx(((())))    member function    that
  2517.       emits    a run-time error (by invoking
  2518.       yyyyyyyyFFFFlllleeeexxxxLLLLeeeexxxxeeeerrrr::::::::LLLLeeeexxxxeeeerrrrEEEErrrrrrrroooorrrr(((()))))))) if    called.     See Generating    C++
  2519.       Scanners, below, for additional information.
  2520.  
  2521.       A number of options are available for    lint purists who want
  2522.       to suppress the appearance of    unneeded routines in the
  2523.       generated scanner.  Each of the following, if    unset (e.g.,
  2524.       %%%%ooooppppttttiiiioooonnnn nnnnoooouuuunnnnppppuuuutttt ), results in    the corresponding routine not
  2525.       appearing in the generated scanner:
  2526.  
  2527.           input, unput
  2528.           yy_push_state, yy_pop_state, yy_top_state
  2529.           yy_scan_buffer, yy_scan_bytes, yy_scan_string
  2530.  
  2531.       (though yyyyyyyy____ppppuuuusssshhhh____ssssttttaaaatttteeee(((()))) and friends won't appear anyway
  2532.       unless you use %%%%ooooppppttttiiiioooonnnn ssssttttaaaacccckkkk))))....
  2533.  
  2534.      PPPPEEEERRRRFFFFOOOORRRRMMMMAAAANNNNCCCCEEEE CCCCOOOONNNNSSSSIIIIDDDDEEEERRRRAAAATTTTIIIIOOOONNNNSSSS
  2535.       The main design goal of _f_l_e_x is that it generate high-
  2536.       performance scanners.     It has    been optimized for dealing
  2537.       well with large sets of rules.  Aside    from the effects on
  2538.       scanner speed    of the table compression ----CCCC options outlined
  2539.       above, there are a number of options/actions which degrade
  2540.       performance.    These are, from    most expensive to least:
  2541.  
  2542.           REJECT
  2543.           %option yylineno
  2544.           arbitrary    trailing context
  2545.  
  2546.           pattern sets that    require    backing    up
  2547.           %array
  2548.           %option interactive
  2549.           %option always-interactive
  2550.  
  2551.           '^' beginning-of-line operator
  2552.           yymore()
  2553.  
  2554.       with the first three all being quite expensive and the last
  2555.       two being quite cheap.  Note also that uuuunnnnppppuuuutttt(((()))) is
  2556.       implemented as a routine call    that potentially does quite a
  2557.       bit of work, while yyyyyyyylllleeeessssssss(((()))) is a quite-cheap macro; so if
  2558.       just putting back some excess    text you scanned, use
  2559.       yyyyyyyylllleeeessssssss(((())))....
  2560.  
  2561.       RRRREEEEJJJJEEEECCCCTTTT should    be avoided at all costs    when performance is
  2562.       important.  It is a particularly expensive option.
  2563.  
  2564.       Getting rid of backing up is messy and often may be an
  2565.       enormous amount of work for a    complicated scanner.  In
  2566.       principal, one begins    by using the ----bbbb    flag to    generate a
  2567.       _l_e_x._b_a_c_k_u_p file.  For    example, on the    input
  2568.  
  2569.  
  2570.  
  2571.      Page 39                         (printed 5/18/98)
  2572.  
  2573.  
  2574.  
  2575.  
  2576.  
  2577.  
  2578.      FFFFLLLLEEEEXXXX((((1111))))         VVVVeeeerrrrssssiiiioooonnnn 2222....5555 ((((AAAApppprrrriiiillll 1111999999995555))))           FFFFLLLLEEEEXXXX((((1111))))
  2579.  
  2580.  
  2581.  
  2582.           %%
  2583.           foo     return    TOK_KEYWORD;
  2584.           foobar     return    TOK_KEYWORD;
  2585.  
  2586.       the file looks like:
  2587.  
  2588.           State #6 is non-accepting    -
  2589.            associated rule line numbers:
  2590.              2         3
  2591.            out-transitions:    [ o ]
  2592.            jam-transitions:    EOF [ \001-n  p-\177 ]
  2593.  
  2594.           State #8 is non-accepting    -
  2595.            associated rule line numbers:
  2596.              3
  2597.            out-transitions:    [ a ]
  2598.            jam-transitions:    EOF [ \001-`  b-\177 ]
  2599.  
  2600.           State #9 is non-accepting    -
  2601.            associated rule line numbers:
  2602.              3
  2603.            out-transitions:    [ r ]
  2604.            jam-transitions:    EOF [ \001-q  s-\177 ]
  2605.  
  2606.           Compressed tables    always back up.
  2607.  
  2608.       The first few    lines tell us that there's a scanner state in
  2609.       which    it can make a transition on an 'o' but not on any
  2610.       other    character, and that in that state the currently
  2611.       scanned text does not    match any rule.     The state occurs when
  2612.       trying to match the rules found at lines 2 and 3 in the
  2613.       input    file.  If the scanner is in that state and then    reads
  2614.       something other than an 'o', it will have to back up to find
  2615.       a rule which is matched.  With a bit of headscratching one
  2616.       can see that this must be the    state it's in when it has seen
  2617.       "fo".     When this has happened, if anything other than
  2618.       another 'o' is seen, the scanner will    have to    back up    to
  2619.       simply match the 'f' (by the default rule).
  2620.  
  2621.       The comment regarding    State #8 indicates there's a problem
  2622.       when "foob" has been scanned.     Indeed, on any    character
  2623.       other    than an    'a', the scanner will have to back up to
  2624.       accept "foo".     Similarly, the    comment    for State #9 concerns
  2625.       when "fooba" has been    scanned    and an 'r' does    not follow.
  2626.  
  2627.       The final comment reminds us that there's no point going to
  2628.       all the trouble of removing backing up from the rules    unless
  2629.       we're    using ----CCCCffff or ----CCCCFFFF,,,, since    there's    no performance gain
  2630.       doing    so with    compressed scanners.
  2631.  
  2632.       The way to remove the    backing    up is to add "error" rules:
  2633.  
  2634.  
  2635.  
  2636.  
  2637.      Page 40                         (printed 5/18/98)
  2638.  
  2639.  
  2640.  
  2641.  
  2642.  
  2643.  
  2644.      FFFFLLLLEEEEXXXX((((1111))))         VVVVeeeerrrrssssiiiioooonnnn 2222....5555 ((((AAAApppprrrriiiillll 1111999999995555))))           FFFFLLLLEEEEXXXX((((1111))))
  2645.  
  2646.  
  2647.  
  2648.           %%
  2649.           foo      return TOK_KEYWORD;
  2650.           foobar      return TOK_KEYWORD;
  2651.  
  2652.           fooba      |
  2653.           foob      |
  2654.           fo      {
  2655.               /* false alarm, not really a keyword */
  2656.               return TOK_ID;
  2657.               }
  2658.  
  2659.  
  2660.       Eliminating backing up among a list of keywords can also be
  2661.       done using a "catch-all" rule:
  2662.  
  2663.           %%
  2664.           foo      return TOK_KEYWORD;
  2665.           foobar      return TOK_KEYWORD;
  2666.  
  2667.           [a-z]+      return TOK_ID;
  2668.  
  2669.       This is usually the best solution when appropriate.
  2670.  
  2671.       Backing up messages tend to cascade.    With a complicated set
  2672.       of rules it's    not uncommon to    get hundreds of    messages.  If
  2673.       one can decipher them, though, it often only takes a dozen
  2674.       or so    rules to eliminate the backing up (though it's easy to
  2675.       make a mistake and have an error rule    accidentally match a
  2676.       valid    token.    A possible future _f_l_e_x feature will be to
  2677.       automatically    add rules to eliminate backing up).
  2678.  
  2679.       It's important to keep in mind that you gain the benefits of
  2680.       eliminating backing up only if you eliminate _e_v_e_r_y instance
  2681.       of backing up.  Leaving just one means you gain nothing.
  2682.  
  2683.       _V_a_r_i_a_b_l_e trailing context (where both    the leading and
  2684.       trailing parts do not    have a fixed length) entails almost
  2685.       the same performance loss as RRRREEEEJJJJEEEECCCCTTTT (i.e., substantial).  So
  2686.       when possible    a rule like:
  2687.  
  2688.           %%
  2689.           mouse|rat/(cat|dog)   run();
  2690.  
  2691.       is better written:
  2692.  
  2693.           %%
  2694.           mouse/cat|dog        run();
  2695.           rat/cat|dog        run();
  2696.  
  2697.       or as
  2698.  
  2699.           %%
  2700.  
  2701.  
  2702.  
  2703.      Page 41                         (printed 5/18/98)
  2704.  
  2705.  
  2706.  
  2707.  
  2708.  
  2709.  
  2710.      FFFFLLLLEEEEXXXX((((1111))))         VVVVeeeerrrrssssiiiioooonnnn 2222....5555 ((((AAAApppprrrriiiillll 1111999999995555))))           FFFFLLLLEEEEXXXX((((1111))))
  2711.  
  2712.  
  2713.  
  2714.           mouse|rat/cat        run();
  2715.           mouse|rat/dog        run();
  2716.  
  2717.       Note that here the special '|' action    does _n_o_t provide any
  2718.       savings, and can even    make things worse (see Deficiencies /
  2719.       Bugs below).
  2720.  
  2721.       Another area where the user can increase a scanner's
  2722.       performance (and one that's easier to    implement) arises from
  2723.       the fact that    the longer the tokens matched, the faster the
  2724.       scanner will run.  This is because with long tokens the
  2725.       processing of    most input characters takes place in the
  2726.       (short) inner    scanning loop, and does    not often have to go
  2727.       through the additional work of setting up the    scanning
  2728.       environment (e.g., yyyyyyyytttteeeexxxxtttt)))) for the action.  Recall the
  2729.       scanner for C    comments:
  2730.  
  2731.           %x comment
  2732.           %%
  2733.               int line_num = 1;
  2734.  
  2735.           "/*"       BEGIN(comment);
  2736.  
  2737.           <comment>[^*\n]*
  2738.           <comment>"*"+[^*/\n]*
  2739.           <comment>\n          ++line_num;
  2740.           <comment>"*"+"/"          BEGIN(INITIAL);
  2741.  
  2742.       This could be    sped up    by writing it as:
  2743.  
  2744.           %x comment
  2745.           %%
  2746.               int line_num = 1;
  2747.  
  2748.           "/*"       BEGIN(comment);
  2749.  
  2750.           <comment>[^*\n]*
  2751.           <comment>[^*\n]*\n      ++line_num;
  2752.           <comment>"*"+[^*/\n]*
  2753.           <comment>"*"+[^*/\n]*\n ++line_num;
  2754.           <comment>"*"+"/"          BEGIN(INITIAL);
  2755.  
  2756.       Now instead of each newline requiring    the processing of
  2757.       another action, recognizing the newlines is "distributed"
  2758.       over the other rules to keep the matched text    as long    as
  2759.       possible.  Note that _a_d_d_i_n_g rules does _n_o_t slow down the
  2760.       scanner!  The    speed of the scanner is    independent of the
  2761.       number of rules or (modulo the considerations    given at the
  2762.       beginning of this section) how complicated the rules are
  2763.       with regard to operators such    as '*' and '|'.
  2764.  
  2765.       A final example in speeding up a scanner: suppose you    want
  2766.  
  2767.  
  2768.  
  2769.      Page 42                         (printed 5/18/98)
  2770.  
  2771.  
  2772.  
  2773.  
  2774.  
  2775.  
  2776.      FFFFLLLLEEEEXXXX((((1111))))         VVVVeeeerrrrssssiiiioooonnnn 2222....5555 ((((AAAApppprrrriiiillll 1111999999995555))))           FFFFLLLLEEEEXXXX((((1111))))
  2777.  
  2778.  
  2779.  
  2780.       to scan through a file containing identifiers    and keywords,
  2781.       one per line and with    no other extraneous characters,    and
  2782.       recognize all    the keywords.  A natural first approach    is:
  2783.  
  2784.           %%
  2785.           asm      |
  2786.           auto     |
  2787.           break    |
  2788.           ... etc ...
  2789.           volatile |
  2790.           while    /* it's a keyword */
  2791.  
  2792.           .|\n     /* it's not a keyword */
  2793.  
  2794.       To eliminate the back-tracking, introduce a catch-all    rule:
  2795.  
  2796.           %%
  2797.           asm      |
  2798.           auto     |
  2799.           break    |
  2800.           ... etc ...
  2801.           volatile |
  2802.           while    /* it's a keyword */
  2803.  
  2804.           [a-z]+   |
  2805.           .|\n     /* it's not a keyword */
  2806.  
  2807.       Now, if it's guaranteed that there's exactly one word    per
  2808.       line,    then we    can reduce the total number of matches by a
  2809.       half by merging in the recognition of    newlines with that of
  2810.       the other tokens:
  2811.  
  2812.           %%
  2813.           asm\n    |
  2814.           auto\n   |
  2815.           break\n  |
  2816.           ... etc ...
  2817.           volatile\n |
  2818.           while\n  /* it's a keyword */
  2819.  
  2820.           [a-z]+\n |
  2821.           .|\n     /* it's not a keyword */
  2822.  
  2823.       One has to be    careful    here, as we have now reintroduced
  2824.       backing up into the scanner.    In particular, while _w_e    know
  2825.       that there will never    be any characters in the input stream
  2826.       other    than letters or    newlines, _f_l_e_x can't figure this out,
  2827.       and it will plan for possibly    needing    to back    up when    it has
  2828.       scanned a token like "auto" and then the next    character is
  2829.       something other than a newline or a letter.  Previously it
  2830.       would    then just match    the "auto" rule    and be done, but now
  2831.       it has no "auto" rule, only a    "auto\n" rule.    To eliminate
  2832.  
  2833.  
  2834.  
  2835.      Page 43                         (printed 5/18/98)
  2836.  
  2837.  
  2838.  
  2839.  
  2840.  
  2841.  
  2842.      FFFFLLLLEEEEXXXX((((1111))))         VVVVeeeerrrrssssiiiioooonnnn 2222....5555 ((((AAAApppprrrriiiillll 1111999999995555))))           FFFFLLLLEEEEXXXX((((1111))))
  2843.  
  2844.  
  2845.  
  2846.       the possibility of backing up, we could either duplicate all
  2847.       rules    but without final newlines, or,    since we never expect
  2848.       to encounter such an input and therefore don't how it's
  2849.       classified, we can introduce one more    catch-all rule,    this
  2850.       one which doesn't include a newline:
  2851.  
  2852.           %%
  2853.           asm\n    |
  2854.           auto\n   |
  2855.           break\n  |
  2856.           ... etc ...
  2857.           volatile\n |
  2858.           while\n  /* it's a keyword */
  2859.  
  2860.           [a-z]+\n |
  2861.           [a-z]+   |
  2862.           .|\n     /* it's not a keyword */
  2863.  
  2864.       Compiled with    ----CCCCffff,,,, this is about as fast as one can get a
  2865.       _f_l_e_x scanner to go for this particular problem.
  2866.  
  2867.       A final note:     _f_l_e_x is slow when matching NUL's,
  2868.       particularly when a token contains multiple NUL's.  It's
  2869.       best to write    rules which match _s_h_o_r_t    amounts    of text    if
  2870.       it's anticipated that    the text will often include NUL's.
  2871.  
  2872.       Another final    note regarding performance: as mentioned above
  2873.       in the section How the Input is Matched, dynamically
  2874.       resizing yyyyyyyytttteeeexxxxtttt to accommodate huge tokens is    a slow process
  2875.       because it presently requires    that the (huge)    token be
  2876.       rescanned from the beginning.     Thus if performance is    vital,
  2877.       you should attempt to    match "large" quantities of text but
  2878.       not "huge" quantities, where the cutoff between the two is
  2879.       at about 8K characters/token.
  2880.  
  2881.      GGGGEEEENNNNEEEERRRRAAAATTTTIIIINNNNGGGG    CCCC++++++++ SSSSCCCCAAAANNNNNNNNEEEERRRRSSSS
  2882.       _f_l_e_x provides    two different ways to generate scanners    for
  2883.       use with C++.     The first way is to simply compile a scanner
  2884.       generated by _f_l_e_x using a C++    compiler instead of a C
  2885.       compiler.  You should    not encounter any compilations errors
  2886.       (please report any you find to the email address given in
  2887.       the Author section below).  You can then use C++ code    in
  2888.       your rule actions instead of C code.    Note that the default
  2889.       input    source for your    scanner    remains    _y_y_i_n, and default
  2890.       echoing is still done    to _y_y_o_u_t. Both of these    remain _F_I_L_E *
  2891.       variables and    not C++    _s_t_r_e_a_m_s.
  2892.  
  2893.       You can also use _f_l_e_x    to generate a C++ scanner class, using
  2894.       the ----++++ option    (or, equivalently, %%%%ooooppppttttiiiioooonnnn cccc++++++++)))),,,, which is
  2895.       automatically    specified if the name of the flex executable
  2896.       ends in a '+', such as _f_l_e_x++. When using this option, flex
  2897.       defaults to generating the scanner to    the file lllleeeexxxx....yyyyyyyy....cccccccc
  2898.  
  2899.  
  2900.  
  2901.      Page 44                         (printed 5/18/98)
  2902.  
  2903.  
  2904.  
  2905.  
  2906.  
  2907.  
  2908.      FFFFLLLLEEEEXXXX((((1111))))         VVVVeeeerrrrssssiiiioooonnnn 2222....5555 ((((AAAApppprrrriiiillll 1111999999995555))))           FFFFLLLLEEEEXXXX((((1111))))
  2909.  
  2910.  
  2911.  
  2912.       instead of lllleeeexxxx....yyyyyyyy....cccc.... The generated scanner includes the
  2913.       header file _F_l_e_x_L_e_x_e_r._h, which defines the interface to two
  2914.       C++ classes.
  2915.  
  2916.       The first class, FFFFlllleeeexxxxLLLLeeeexxxxeeeerrrr,,,, provides an abstract base    class
  2917.       defining the general scanner class interface.     It provides
  2918.       the following    member functions:
  2919.  
  2920.       ccccoooonnnnsssstttt    cccchhhhaaaarrrr**** YYYYYYYYTTTTeeeexxxxtttt(((())))
  2921.            returns the text    of the most recently matched token,
  2922.            the equivalent of yyyyyyyytttteeeexxxxtttt....
  2923.  
  2924.       iiiinnnntttt YYYYYYYYLLLLeeeennnngggg(((())))
  2925.            returns the length of the most recently matched token,
  2926.            the equivalent of yyyyyyyylllleeeennnngggg....
  2927.  
  2928.       iiiinnnntttt lllliiiinnnneeeennnnoooo(((()))) ccccoooonnnnsssstttt
  2929.            returns the current input line number (see %%%%ooooppppttttiiiioooonnnn
  2930.            yyyyyyyylllliiiinnnneeeennnnoooo)))),,,, or 1111 if %%%%ooooppppttttiiiioooonnnn yyyyyyyylllliiiinnnneeeennnnoooo was not used.
  2931.  
  2932.       vvvvooooiiiidddd sssseeeetttt____ddddeeeebbbbuuuugggg(((( iiiinnnntttt ffffllllaaaagggg ))))
  2933.            sets the    debugging flag for the scanner,    equivalent to
  2934.            assigning to yyyyyyyy____fffflllleeeexxxx____ddddeeeebbbbuuuugggg (see the Options section
  2935.            above).    Note that you must build the scanner using
  2936.            %%%%ooooppppttttiiiioooonnnn ddddeeeebbbbuuuugggg to    include    debugging information in it.
  2937.  
  2938.       iiiinnnntttt ddddeeeebbbbuuuugggg(((()))) ccccoooonnnnsssstttt
  2939.            returns the current setting of the debugging flag.
  2940.  
  2941.       Also provided    are member functions equivalent    to
  2942.       yyyyyyyy____sssswwwwiiiittttcccchhhh____ttttoooo____bbbbuuuuffffffffeeeerrrr(((()))),,,, yyyyyyyy____ccccrrrreeeeaaaatttteeee____bbbbuuuuffffffffeeeerrrr(((()))) (though the    first
  2943.       argument is an iiiissssttttrrrreeeeaaaammmm**** object pointer and not a FFFFIIIILLLLEEEE****)))),,,,
  2944.       yyyyyyyy____fffflllluuuusssshhhh____bbbbuuuuffffffffeeeerrrr(((()))),,,, yyyyyyyy____ddddeeeelllleeeetttteeee____bbbbuuuuffffffffeeeerrrr(((()))),,,, and yyyyyyyyrrrreeeessssttttaaaarrrrtttt(((())))
  2945.       (again, the first argument is    a iiiissssttttrrrreeeeaaaammmm**** object pointer).
  2946.  
  2947.       The second class defined in _F_l_e_x_L_e_x_e_r._h is yyyyyyyyFFFFlllleeeexxxxLLLLeeeexxxxeeeerrrr,,,,
  2948.       which    is derived from    FFFFlllleeeexxxxLLLLeeeexxxxeeeerrrr.... It defines the following
  2949.       additional member functions:
  2950.  
  2951.       yyyyyyyyFFFFlllleeeexxxxLLLLeeeexxxxeeeerrrr(((( iiiissssttttrrrreeeeaaaammmm****    aaaarrrrgggg____yyyyyyyyiiiinnnn ==== 0000,,,, oooossssttttrrrreeeeaaaammmm**** aaaarrrrgggg____yyyyyyyyoooouuuutttt ==== 0000 ))))
  2952.            constructs a yyyyyyyyFFFFlllleeeexxxxLLLLeeeexxxxeeeerrrr    object using the given streams
  2953.            for input and output.  If not specified,    the streams
  2954.            default to cccciiiinnnn and ccccoooouuuutttt,,,,    respectively.
  2955.  
  2956.       vvvviiiirrrrttttuuuuaaaallll iiiinnnntttt yyyyyyyylllleeeexxxx(((())))
  2957.            performs    the same role is yyyyyyyylllleeeexxxx(((()))) does for ordinary
  2958.            flex scanners: it scans the input stream, consuming
  2959.            tokens, until a rule's action returns a value.  If you
  2960.            derive a    subclass SSSS from    yyyyyyyyFFFFlllleeeexxxxLLLLeeeexxxxeeeerrrr and    want to    access
  2961.            the member functions and    variables of SSSS inside yyyyyyyylllleeeexxxx(((()))),,,,
  2962.            then you    need to    use %%%%ooooppppttttiiiioooonnnn yyyyyyyyccccllllaaaassssssss====""""SSSS""""    to inform _f_l_e_x
  2963.            that you    will be    using that subclass instead of
  2964.  
  2965.  
  2966.  
  2967.      Page 45                         (printed 5/18/98)
  2968.  
  2969.  
  2970.  
  2971.  
  2972.  
  2973.  
  2974.      FFFFLLLLEEEEXXXX((((1111))))         VVVVeeeerrrrssssiiiioooonnnn 2222....5555 ((((AAAApppprrrriiiillll 1111999999995555))))           FFFFLLLLEEEEXXXX((((1111))))
  2975.  
  2976.  
  2977.  
  2978.            yyyyyyyyFFFFlllleeeexxxxLLLLeeeexxxxeeeerrrr.... In this case, rather than generating
  2979.            yyyyyyyyFFFFlllleeeexxxxLLLLeeeexxxxeeeerrrr::::::::yyyyyyyylllleeeexxxx(((()))),,,, _f_l_e_x generates SSSS::::::::yyyyyyyylllleeeexxxx(((()))) (and
  2980.            also generates a    dummy yyyyyyyyFFFFlllleeeexxxxLLLLeeeexxxxeeeerrrr::::::::yyyyyyyylllleeeexxxx(((()))) that    calls
  2981.            yyyyyyyyFFFFlllleeeexxxxLLLLeeeexxxxeeeerrrr::::::::LLLLeeeexxxxeeeerrrrEEEErrrrrrrroooorrrr(((()))) if called).
  2982.  
  2983.       vvvviiiirrrrttttuuuuaaaallll vvvvooooiiiidddd sssswwwwiiiittttcccchhhh____ssssttttrrrreeeeaaaammmmssss((((iiiissssttttrrrreeeeaaaammmm**** nnnneeeewwww____iiiinnnn ====    0000,,,,
  2984.            oooossssttttrrrreeeeaaaammmm****    nnnneeeewwww____oooouuuutttt    ==== 0000)))) reassigns yyyyyyyyiiiinnnn to nnnneeeewwww____iiiinnnn (if
  2985.            non-nil)    and yyyyyyyyoooouuuutttt to nnnneeeewwww____oooouuuutttt (ditto), deleting the
  2986.            previous    input buffer if    yyyyyyyyiiiinnnn is    reassigned.
  2987.  
  2988.       iiiinnnntttt yyyyyyyylllleeeexxxx(((( iiiissssttttrrrreeeeaaaammmm**** nnnneeeewwww____iiiinnnn,,,, oooossssttttrrrreeeeaaaammmm**** nnnneeeewwww____oooouuuutttt ==== 0000 ))))
  2989.            first switches the input    streams    via sssswwwwiiiittttcccchhhh____ssssttttrrrreeeeaaaammmmssss((((
  2990.            nnnneeeewwww____iiiinnnn,,,, nnnneeeewwww____oooouuuutttt )))) and then returns the value of
  2991.            yyyyyyyylllleeeexxxx(((())))....
  2992.  
  2993.       In addition, yyyyyyyyFFFFlllleeeexxxxLLLLeeeexxxxeeeerrrr defines the following protected
  2994.       virtual functions which you can redefine in derived classes
  2995.       to tailor the    scanner:
  2996.  
  2997.       vvvviiiirrrrttttuuuuaaaallll iiiinnnntttt LLLLeeeexxxxeeeerrrrIIIInnnnppppuuuutttt(((( cccchhhhaaaarrrr****    bbbbuuuuffff,,,, iiiinnnntttt mmmmaaaaxxxx____ssssiiiizzzzeeee ))))
  2998.            reads up    to mmmmaaaaxxxx____ssssiiiizzzzeeee characters into bbbbuuuuffff    and returns
  2999.            the number of characters    read.  To indicate end-of-
  3000.            input, return 0 characters.  Note that "interactive"
  3001.            scanners    (see the ----BBBB and    ----IIII flags) define the macro
  3002.            YYYYYYYY____IIIINNNNTTTTEEEERRRRAAAACCCCTTTTIIIIVVVVEEEE.... If you redefine LLLLeeeexxxxeeeerrrrIIIInnnnppppuuuutttt(((()))) and    need
  3003.            to take different actions depending on whether or not
  3004.            the scanner might be scanning an    interactive input
  3005.            source, you can test for    the presence of    this name via
  3006.            ####iiiiffffddddeeeeffff....
  3007.  
  3008.       vvvviiiirrrrttttuuuuaaaallll vvvvooooiiiidddd LLLLeeeexxxxeeeerrrrOOOOuuuuttttppppuuuutttt(((( ccccoooonnnnsssstttt cccchhhhaaaarrrr****    bbbbuuuuffff,,,, iiiinnnntttt ssssiiiizzzzeeee ))))
  3009.            writes out ssssiiiizzzzeeee characters from the buffer bbbbuuuuffff,,,, which,
  3010.            while NUL-terminated, may also contain "internal" NUL's
  3011.            if the scanner's    rules can match    text with NUL's    in
  3012.            them.
  3013.  
  3014.       vvvviiiirrrrttttuuuuaaaallll vvvvooooiiiidddd LLLLeeeexxxxeeeerrrrEEEErrrrrrrroooorrrr(((( ccccoooonnnnsssstttt cccchhhhaaaarrrr**** mmmmssssgggg ))))
  3015.            reports a fatal error message.  The default version of
  3016.            this function writes the    message    to the stream cccceeeerrrrrrrr and
  3017.            exits.
  3018.  
  3019.       Note that a yyyyyyyyFFFFlllleeeexxxxLLLLeeeexxxxeeeerrrr object contains its _e_n_t_i_r_e scanning
  3020.       state.  Thus you can use such    objects    to create reentrant
  3021.       scanners.  You can instantiate multiple instances of the
  3022.       same yyyyyyyyFFFFlllleeeexxxxLLLLeeeexxxxeeeerrrr class, and you can also combine multiple
  3023.       C++ scanner classes together in the same program using the
  3024.       ----PPPP option discussed above.
  3025.  
  3026.       Finally, note    that the %%%%aaaarrrrrrrraaaayyyy    feature    is not available to
  3027.       C++ scanner classes; you must    use %%%%ppppooooiiiinnnntttteeeerrrr (the default).
  3028.  
  3029.       Here is an example of    a simple C++ scanner:
  3030.  
  3031.  
  3032.  
  3033.      Page 46                         (printed 5/18/98)
  3034.  
  3035.  
  3036.  
  3037.  
  3038.  
  3039.  
  3040.      FFFFLLLLEEEEXXXX((((1111))))         VVVVeeeerrrrssssiiiioooonnnn 2222....5555 ((((AAAApppprrrriiiillll 1111999999995555))))           FFFFLLLLEEEEXXXX((((1111))))
  3041.  
  3042.  
  3043.  
  3044.           // An    example    of using the flex C++ scanner class.
  3045.  
  3046.           %{
  3047.           int mylineno = 0;
  3048.           %}
  3049.  
  3050.           string  \"[^\n"]+\"
  3051.  
  3052.           ws      [    \t]+
  3053.  
  3054.           alpha   [A-Za-z]
  3055.           dig     [0-9]
  3056.           name    ({alpha}|{dig}|\$)({alpha}|{dig}|[_.\-/$])*
  3057.           num1    [-+]?{dig}+\.?([eE][-+]?{dig}+)?
  3058.           num2    [-+]?{dig}*\.{dig}+([eE][-+]?{dig}+)?
  3059.           number  {num1}|{num2}
  3060.  
  3061.           %%
  3062.  
  3063.           {ws}    /* skip blanks and tabs */
  3064.  
  3065.           "/*"    {
  3066.               int c;
  3067.  
  3068.               while((c = yyinput()) != 0)
  3069.               {
  3070.               if(c == '\n')
  3071.                   ++mylineno;
  3072.  
  3073.               else if(c == '*')
  3074.                   {
  3075.                   if((c = yyinput()) == '/')
  3076.                   break;
  3077.                   else
  3078.                   unput(c);
  3079.                   }
  3080.               }
  3081.               }
  3082.  
  3083.           {number}    cout <<    "number    " << YYText() << '\n';
  3084.  
  3085.           \n    mylineno++;
  3086.  
  3087.           {name}    cout <<    "name "    << YYText() << '\n';
  3088.  
  3089.           {string}    cout <<    "string    " << YYText() << '\n';
  3090.  
  3091.           %%
  3092.  
  3093.           int main(    int /* argc */,    char** /* argv */ )
  3094.           {
  3095.           FlexLexer* lexer = new yyFlexLexer;
  3096.  
  3097.  
  3098.  
  3099.      Page 47                         (printed 5/18/98)
  3100.  
  3101.  
  3102.  
  3103.  
  3104.  
  3105.  
  3106.      FFFFLLLLEEEEXXXX((((1111))))         VVVVeeeerrrrssssiiiioooonnnn 2222....5555 ((((AAAApppprrrriiiillll 1111999999995555))))           FFFFLLLLEEEEXXXX((((1111))))
  3107.  
  3108.  
  3109.  
  3110.           while(lexer->yylex() != 0)
  3111.               ;
  3112.           return 0;
  3113.           }
  3114.       If you want to create    multiple (different) lexer classes,
  3115.       you use the ----PPPP flag (or the pppprrrreeeeffffiiiixxxx==== option) to rename    each
  3116.       yyyyyyyyFFFFlllleeeexxxxLLLLeeeexxxxeeeerrrr to some other xxxxxxxxFFFFlllleeeexxxxLLLLeeeexxxxeeeerrrr.... You then can include
  3117.       <<<<FFFFlllleeeexxxxLLLLeeeexxxxeeeerrrr....hhhh>>>>    in your    other sources once per lexer class,
  3118.       first    renaming yyyyyyyyFFFFlllleeeexxxxLLLLeeeexxxxeeeerrrr as    follows:
  3119.  
  3120.           #undef yyFlexLexer
  3121.           #define yyFlexLexer xxFlexLexer
  3122.           #include <FlexLexer.h>
  3123.  
  3124.           #undef yyFlexLexer
  3125.           #define yyFlexLexer zzFlexLexer
  3126.           #include <FlexLexer.h>
  3127.  
  3128.       if, for example, you used %%%%ooooppppttttiiiioooonnnn pppprrrreeeeffffiiiixxxx====""""xxxxxxxx""""    for one    of
  3129.       your scanners    and %%%%ooooppppttttiiiioooonnnn pppprrrreeeeffffiiiixxxx====""""zzzzzzzz""""    for the    other.
  3130.  
  3131.       IMPORTANT: the present form of the scanning class is
  3132.       _e_x_p_e_r_i_m_e_n_t_a_l and may change considerably between major
  3133.       releases.
  3134.  
  3135.      IIIINNNNCCCCOOOOMMMMPPPPAAAATTTTIIIIBBBBIIIILLLLIIIITTTTIIIIEEEESSSS WWWWIIIITTTTHHHH LLLLEEEEXXXX    AAAANNNNDDDD PPPPOOOOSSSSIIIIXXXX
  3136.       _f_l_e_x is a rewrite of the AT&T    Unix _l_e_x tool (the two
  3137.       implementations do not share any code, though), with some
  3138.       extensions and incompatibilities, both of which are of
  3139.       concern to those who wish to write scanners acceptable to
  3140.       either implementation.  Flex is fully    compliant with the
  3141.       POSIX    _l_e_x specification, except that when using %%%%ppppooooiiiinnnntttteeeerrrr
  3142.       (the default), a call    to uuuunnnnppppuuuutttt(((()))) destroys the    contents of
  3143.       yyyyyyyytttteeeexxxxtttt,,,, which    is counter to the POSIX    specification.
  3144.  
  3145.       In this section we discuss all of the    known areas of
  3146.       incompatibility between flex,    AT&T lex, and the POSIX
  3147.       specification.
  3148.  
  3149.       _f_l_e_x'_s ----llll option turns on maximum compatibility with the
  3150.       original AT&T    _l_e_x implementation, at the cost    of a major
  3151.       loss in the generated    scanner's performance.    We note    below
  3152.       which    incompatibilities can be overcome using    the ----llll option.
  3153.  
  3154.       _f_l_e_x is fully    compatible with    _l_e_x with the following
  3155.       exceptions:
  3156.  
  3157.       -    The undocumented    _l_e_x scanner internal variable yyyyyyyylllliiiinnnneeeennnnoooo
  3158.            is not supported    unless ----llll or %%%%ooooppppttttiiiioooonnnn yyyyyyyylllliiiinnnneeeennnnoooo is used.
  3159.  
  3160.            yyyyyyyylllliiiinnnneeeennnnoooo    should be maintained on    a per-buffer basis,
  3161.            rather than a per-scanner (single global    variable)
  3162.  
  3163.  
  3164.  
  3165.      Page 48                         (printed 5/18/98)
  3166.  
  3167.  
  3168.  
  3169.  
  3170.  
  3171.  
  3172.      FFFFLLLLEEEEXXXX((((1111))))         VVVVeeeerrrrssssiiiioooonnnn 2222....5555 ((((AAAApppprrrriiiillll 1111999999995555))))           FFFFLLLLEEEEXXXX((((1111))))
  3173.  
  3174.  
  3175.  
  3176.            basis.
  3177.  
  3178.            yyyyyyyylllliiiinnnneeeennnnoooo    is not part of the POSIX specification.
  3179.  
  3180.       -    The iiiinnnnppppuuuutttt(((()))) routine is not redefinable, though it may
  3181.            be called to read characters following whatever has
  3182.            been matched by a rule.    If iiiinnnnppppuuuutttt(((()))) encounters an end-
  3183.            of-file the normal yyyyyyyywwwwrrrraaaapppp(((()))) processing is done.    A
  3184.            ``real''    end-of-file is returned    by iiiinnnnppppuuuutttt(((()))) as _E_O_F.
  3185.  
  3186.            Input is    instead    controlled by defining the YYYYYYYY____IIIINNNNPPPPUUUUTTTT
  3187.            macro.
  3188.  
  3189.            The _f_l_e_x    restriction that iiiinnnnppppuuuutttt(((()))) cannot    be redefined
  3190.            is in accordance    with the POSIX specification, which
  3191.            simply does not specify any way of controlling the
  3192.            scanner's input other than by making an initial
  3193.            assignment to _y_y_i_n.
  3194.  
  3195.       -    The uuuunnnnppppuuuutttt(((()))) routine is not redefinable.    This
  3196.            restriction is in accordance with POSIX.
  3197.  
  3198.       -    _f_l_e_x scanners are not as    reentrant as _l_e_x scanners.  In
  3199.            particular, if you have an interactive scanner and an
  3200.            interrupt handler which long-jumps out of the scanner,
  3201.            and the scanner is subsequently called again, you may
  3202.            get the following message:
  3203.  
  3204.            fatal flex scanner internal error--end of buffer missed
  3205.  
  3206.            To reenter the scanner, first use
  3207.  
  3208.            yyrestart( yyin );
  3209.  
  3210.            Note that this call will    throw away any buffered    input;
  3211.            usually this isn't a problem with an interactive
  3212.            scanner.
  3213.  
  3214.            Also note that flex C++ scanner classes _a_r_e reentrant,
  3215.            so if using C++ is an option for    you, you should    use
  3216.            them instead.  See "Generating C++ Scanners" above for
  3217.            details.
  3218.  
  3219.       -    oooouuuuttttppppuuuutttt(((())))    is not supported.  Output from the EEEECCCCHHHHOOOO    macro
  3220.            is done to the file-pointer _y_y_o_u_t (default _s_t_d_o_u_t).
  3221.  
  3222.            oooouuuuttttppppuuuutttt(((())))    is not part of the POSIX specification.
  3223.  
  3224.       -    _l_e_x does    not support exclusive start conditions (%x),
  3225.            though they are in the POSIX specification.
  3226.  
  3227.       -    When definitions    are expanded, _f_l_e_x encloses them in
  3228.  
  3229.  
  3230.  
  3231.      Page 49                         (printed 5/18/98)
  3232.  
  3233.  
  3234.  
  3235.  
  3236.  
  3237.  
  3238.      FFFFLLLLEEEEXXXX((((1111))))         VVVVeeeerrrrssssiiiioooonnnn 2222....5555 ((((AAAApppprrrriiiillll 1111999999995555))))           FFFFLLLLEEEEXXXX((((1111))))
  3239.  
  3240.  
  3241.  
  3242.            parentheses.  With lex, the following:
  3243.  
  3244.            NAME       [A-Z][A-Z0-9]*
  3245.            %%
  3246.            foo{NAME}?       printf( "Found it\n"    );
  3247.            %%
  3248.  
  3249.            will not    match the string "foo" because when the    macro
  3250.            is expanded the rule is equivalent to "foo[A-Z][A-Z0-
  3251.            9]*?"  and the precedence is such that the '?' is
  3252.            associated with "[A-Z0-9]*".  With _f_l_e_x,    the rule will
  3253.            be expanded to "foo([A-Z][A-Z0-9]*)?" and so the    string
  3254.            "foo" will match.
  3255.  
  3256.            Note that if the    definition begins with ^^^^ or ends with
  3257.            $$$$ then it is _n_o_t    expanded with parentheses, to allow
  3258.            these operators to appear in definitions    without    losing
  3259.            their special meanings.    But the    <<<<ssss>>>>,,,, ////,,,,    and <<<<<<<<EEEEOOOOFFFF>>>>>>>>
  3260.            operators cannot    be used    in a _f_l_e_x definition.
  3261.  
  3262.            Using ----llll    results    in the _l_e_x behavior of no parentheses
  3263.            around the definition.
  3264.  
  3265.            The POSIX specification is that the definition be
  3266.            enclosed    in parentheses.
  3267.  
  3268.       -    Some implementations of _l_e_x allow a rule's action to
  3269.            begin on    a separate line, if the    rule's pattern has
  3270.            trailing    whitespace:
  3271.  
  3272.            %%
  3273.            foo|bar<space here>
  3274.              { foobar_action();    }
  3275.  
  3276.            _f_l_e_x does not support this feature.
  3277.  
  3278.       -    The _l_e_x %%%%rrrr (generate a Ratfor scanner) option is    not
  3279.            supported.  It is not part of the POSIX specification.
  3280.  
  3281.       -    After a call to uuuunnnnppppuuuutttt(((()))),,,,    _y_y_t_e_x_t is undefined until the
  3282.            next token is matched, unless the scanner was built
  3283.            using %%%%aaaarrrrrrrraaaayyyy.... This is not the case with _l_e_x or the
  3284.            POSIX specification.  The ----llll option does    away with this
  3285.            incompatibility.
  3286.  
  3287.       -    The precedence of the {{{{}}}}    (numeric range)    operator is
  3288.            different.  _l_e_x interprets "abc{1,3}" as    "match one,
  3289.            two, or three occurrences of 'abc'", whereas _f_l_e_x
  3290.            interprets it as    "match 'ab' followed by    one, two, or
  3291.            three occurrences of 'c'".  The latter is in agreement
  3292.            with the    POSIX specification.
  3293.  
  3294.  
  3295.  
  3296.  
  3297.      Page 50                         (printed 5/18/98)
  3298.  
  3299.  
  3300.  
  3301.  
  3302.  
  3303.  
  3304.      FFFFLLLLEEEEXXXX((((1111))))         VVVVeeeerrrrssssiiiioooonnnn 2222....5555 ((((AAAApppprrrriiiillll 1111999999995555))))           FFFFLLLLEEEEXXXX((((1111))))
  3305.  
  3306.  
  3307.  
  3308.       -    The precedence of the ^^^^ operator    is different.  _l_e_x
  3309.            interprets "^foo|bar" as    "match either 'foo' at the
  3310.            beginning of a line, or 'bar' anywhere",    whereas    _f_l_e_x
  3311.            interprets it as    "match either 'foo' or 'bar' if    they
  3312.            come at the beginning of    a line".  The latter is    in
  3313.            agreement with the POSIX    specification.
  3314.  
  3315.       -    The special table-size declarations such    as %%%%aaaa
  3316.            supported by _l_e_x    are not    required by _f_l_e_x scanners;
  3317.            _f_l_e_x ignores them.
  3318.  
  3319.       -    The name    FLEX_SCANNER is    #define'd so scanners may be
  3320.            written for use with either _f_l_e_x    or _l_e_x.    Scanners also
  3321.            include YYYYYYYY____FFFFLLLLEEEEXXXX____MMMMAAAAJJJJOOOORRRR____VVVVEEEERRRRSSSSIIIIOOOONNNN and YYYYYYYY____FFFFLLLLEEEEXXXX____MMMMIIIINNNNOOOORRRR____VVVVEEEERRRRSSSSIIIIOOOONNNN
  3322.            indicating which    version    of _f_l_e_x    generated the scanner
  3323.            (for example, for the 2.5 release, these    defines    would
  3324.            be 2 and    5 respectively).
  3325.  
  3326.       The following    _f_l_e_x features are not included in _l_e_x or the
  3327.       POSIX    specification:
  3328.  
  3329.           C++ scanners
  3330.           %option
  3331.           start condition scopes
  3332.           start condition stacks
  3333.           interactive/non-interactive scanners
  3334.           yy_scan_string() and friends
  3335.           yyterminate()
  3336.           yy_set_interactive()
  3337.           yy_set_bol()
  3338.           YY_AT_BOL()
  3339.           <<EOF>>
  3340.           <*>
  3341.           YY_DECL
  3342.           YY_START
  3343.           YY_USER_ACTION
  3344.           YY_USER_INIT
  3345.           #line directives
  3346.           %{}'s around actions
  3347.           multiple actions on a line
  3348.  
  3349.       plus almost all of the flex flags.  The last feature in the
  3350.       list refers to the fact that with _f_l_e_x you can put multiple
  3351.       actions on the same line, separated with semi-colons,    while
  3352.       with _l_e_x, the    following
  3353.  
  3354.           foo    handle_foo(); ++num_foos_seen;
  3355.  
  3356.       is (rather surprisingly) truncated to
  3357.  
  3358.           foo    handle_foo();
  3359.  
  3360.  
  3361.  
  3362.  
  3363.      Page 51                         (printed 5/18/98)
  3364.  
  3365.  
  3366.  
  3367.  
  3368.  
  3369.  
  3370.      FFFFLLLLEEEEXXXX((((1111))))         VVVVeeeerrrrssssiiiioooonnnn 2222....5555 ((((AAAApppprrrriiiillll 1111999999995555))))           FFFFLLLLEEEEXXXX((((1111))))
  3371.  
  3372.  
  3373.  
  3374.       _f_l_e_x does not    truncate the action.  Actions that are not
  3375.       enclosed in braces are simply    terminated at the end of the
  3376.       line.
  3377.  
  3378.      DDDDIIIIAAAAGGGGNNNNOOOOSSSSTTTTIIIICCCCSSSS
  3379.       _w_a_r_n_i_n_g, _r_u_l_e    _c_a_n_n_o_t _b_e _m_a_t_c_h_e_d indicates that the given
  3380.       rule cannot be matched because it follows other rules    that
  3381.       will always match the    same text as it.  For example, in the
  3382.       following "foo" cannot be matched because it comes after an
  3383.       identifier "catch-all" rule:
  3384.  
  3385.           [a-z]+    got_identifier();
  3386.           foo    got_foo();
  3387.  
  3388.       Using    RRRREEEEJJJJEEEECCCCTTTT in a scanner suppresses this warning.
  3389.  
  3390.       _w_a_r_n_i_n_g, ----ssss _o_p_t_i_o_n _g_i_v_e_n _b_u_t _d_e_f_a_u_l_t _r_u_l_e _c_a_n    _b_e _m_a_t_c_h_e_d
  3391.       means    that it    is possible (perhaps only in a particular
  3392.       start    condition) that    the default rule (match    any single
  3393.       character) is    the only one that will match a particular
  3394.       input.  Since    ----ssss was given, presumably this is not intended.
  3395.  
  3396.       _r_e_j_e_c_t__u_s_e_d__b_u_t__n_o_t__d_e_t_e_c_t_e_d _u_n_d_e_f_i_n_e_d or
  3397.       _y_y_m_o_r_e__u_s_e_d__b_u_t__n_o_t__d_e_t_e_c_t_e_d _u_n_d_e_f_i_n_e_d - These errors    can
  3398.       occur    at compile time.  They indicate    that the scanner uses
  3399.       RRRREEEEJJJJEEEECCCCTTTT or yyyyyyyymmmmoooorrrreeee(((()))) but that _f_l_e_x failed to notice the    fact,
  3400.       meaning that _f_l_e_x scanned the    first two sections looking for
  3401.       occurrences of these actions and failed to find any, but
  3402.       somehow you snuck some in (via a #include file, for
  3403.       example).  Use %%%%ooooppppttttiiiioooonnnn rrrreeeejjjjeeeecccctttt    or %%%%ooooppppttttiiiioooonnnn yyyyyyyymmmmoooorrrreeee to indicate
  3404.       to flex that you really do use these features.
  3405.  
  3406.       _f_l_e_x _s_c_a_n_n_e_r _j_a_m_m_e_d -    a scanner compiled with    ----ssss has
  3407.       encountered an input string which wasn't matched by any of
  3408.       its rules.  This error can also occur    due to internal
  3409.       problems.
  3410.  
  3411.       _t_o_k_e_n    _t_o_o _l_a_r_g_e, _e_x_c_e_e_d_s _Y_Y_L_M_A_X - your scanner uses %%%%aaaarrrrrrrraaaayyyy
  3412.       and one of its rules matched a string    longer than the    YYYYYYYYLLLLMMMMAAAAXXXX
  3413.       constant (8K bytes by    default).  You can increase the    value
  3414.       by #define'ing YYYYYYYYLLLLMMMMAAAAXXXX    in the definitions section of your
  3415.       _f_l_e_x input.
  3416.  
  3417.       _s_c_a_n_n_e_r _r_e_q_u_i_r_e_s -_8 _f_l_a_g _t_o _u_s_e _t_h_e _c_h_a_r_a_c_t_e_r    '_x' - Your
  3418.       scanner specification    includes recognizing the 8-bit
  3419.       character '_x'    and you    did not    specify    the -8 flag, and your
  3420.       scanner defaulted to 7-bit because you used the ----CCCCffff or ----CCCCFFFF
  3421.       table    compression options.  See the discussion of the    ----7777
  3422.       flag for details.
  3423.  
  3424.       _f_l_e_x _s_c_a_n_n_e_r _p_u_s_h-_b_a_c_k _o_v_e_r_f_l_o_w - you    used uuuunnnnppppuuuutttt(((()))) to    push
  3425.       back so much text that the scanner's buffer could not    hold
  3426.  
  3427.  
  3428.  
  3429.      Page 52                         (printed 5/18/98)
  3430.  
  3431.  
  3432.  
  3433.  
  3434.  
  3435.  
  3436.      FFFFLLLLEEEEXXXX((((1111))))         VVVVeeeerrrrssssiiiioooonnnn 2222....5555 ((((AAAApppprrrriiiillll 1111999999995555))))           FFFFLLLLEEEEXXXX((((1111))))
  3437.  
  3438.  
  3439.  
  3440.       both the pushed-back text and    the current token in yyyyyyyytttteeeexxxxtttt....
  3441.       Ideally the scanner should dynamically resize    the buffer in
  3442.       this case, but at present it does not.
  3443.  
  3444.       _i_n_p_u_t    _b_u_f_f_e_r _o_v_e_r_f_l_o_w, _c_a_n'_t _e_n_l_a_r_g_e _b_u_f_f_e_r _b_e_c_a_u_s_e _s_c_a_n_n_e_r
  3445.       _u_s_e_s _R_E_J_E_C_T -    the scanner was    working    on matching an
  3446.       extremely large token    and needed to expand the input buffer.
  3447.       This doesn't work with scanners that use RRRREEEEJJJJEEEECCCCTTTT....
  3448.  
  3449.       _f_a_t_a_l    _f_l_e_x _s_c_a_n_n_e_r _i_n_t_e_r_n_a_l _e_r_r_o_r--_e_n_d _o_f _b_u_f_f_e_r _m_i_s_s_e_d -
  3450.       This can occur in an scanner which is    reentered after    a
  3451.       long-jump has    jumped out (or over) the scanner's activation
  3452.       frame.  Before reentering the    scanner, use:
  3453.  
  3454.           yyrestart( yyin );
  3455.  
  3456.       or, as noted above, switch to    using the C++ scanner class.
  3457.  
  3458.       _t_o_o _m_a_n_y _s_t_a_r_t _c_o_n_d_i_t_i_o_n_s _i_n <> you listed more start
  3459.       conditions in    a <> construct than exist (so you must have
  3460.       listed at least one of them twice).
  3461.  
  3462.      FFFFIIIILLLLEEEESSSS
  3463.       ----llllffffllll library with which scanners must    be linked.
  3464.  
  3465.       _l_e_x._y_y._c
  3466.            generated scanner (called _l_e_x_y_y._c on some systems).
  3467.  
  3468.       _l_e_x._y_y._c_c
  3469.            generated C++ scanner class, when using ----++++....
  3470.  
  3471.       <_F_l_e_x_L_e_x_e_r._h>
  3472.            header file defining the    C++ scanner base class,
  3473.            FFFFlllleeeexxxxLLLLeeeexxxxeeeerrrr,,,, and its derived class, yyyyyyyyFFFFlllleeeexxxxLLLLeeeexxxxeeeerrrr....
  3474.  
  3475.       _f_l_e_x._s_k_l
  3476.            skeleton    scanner.  This file is only used when building
  3477.            flex, not when flex executes.
  3478.  
  3479.       _l_e_x._b_a_c_k_u_p
  3480.            backing-up information for ----bbbb flag (called _l_e_x._b_c_k on
  3481.            some systems).
  3482.  
  3483.      DDDDEEEEFFFFIIIICCCCIIIIEEEENNNNCCCCIIIIEEEESSSS //// BBBBUUUUGGGGSSSS
  3484.       Some trailing    context    patterns cannot    be properly matched
  3485.       and generate warning messages    ("dangerous trailing
  3486.       context").  These are    patterns where the ending of the first
  3487.       part of the rule matches the beginning of the    second part,
  3488.       such as "zx*/xy*", where the 'x*' matches the    'x' at the
  3489.       beginning of the trailing context.  (Note that the POSIX
  3490.       draft    states that the    text matched by    such patterns is
  3491.       undefined.)
  3492.  
  3493.  
  3494.  
  3495.      Page 53                         (printed 5/18/98)
  3496.  
  3497.  
  3498.  
  3499.  
  3500.  
  3501.  
  3502.      FFFFLLLLEEEEXXXX((((1111))))         VVVVeeeerrrrssssiiiioooonnnn 2222....5555 ((((AAAApppprrrriiiillll 1111999999995555))))           FFFFLLLLEEEEXXXX((((1111))))
  3503.  
  3504.  
  3505.  
  3506.       For some trailing context rules, parts which are actually
  3507.       fixed-length are not recognized as such, leading to the
  3508.       abovementioned performance loss.  In particular, parts using
  3509.       '|' or {n} (such as "foo{3}")    are always considered
  3510.       variable-length.
  3511.  
  3512.       Combining trailing context with the special '|' action can
  3513.       result in _f_i_x_e_d trailing context being turned    into the more
  3514.       expensive _v_a_r_i_a_b_l_e trailing context.    For example, in    the
  3515.       following:
  3516.  
  3517.           %%
  3518.           abc      |
  3519.           xyz/def
  3520.  
  3521.  
  3522.       Use of uuuunnnnppppuuuutttt(((()))) invalidates yytext and    yyleng,    unless the
  3523.       %%%%aaaarrrrrrrraaaayyyy directive or the ----llll option has    been used.
  3524.  
  3525.       Pattern-matching of NUL's is substantially slower than
  3526.       matching other characters.
  3527.  
  3528.       Dynamic resizing of the input    buffer is slow,    as it entails
  3529.       rescanning all the text matched so far by the    current
  3530.       (generally huge) token.
  3531.  
  3532.       Due to both buffering    of input and read-ahead, you cannot
  3533.       intermix calls to <stdio.h> routines,    such as, for example,
  3534.       ggggeeeettttcccchhhhaaaarrrr(((()))),,,, with _f_l_e_x rules and expect    it to work.  Call
  3535.       iiiinnnnppppuuuutttt(((()))) instead.
  3536.  
  3537.       The total table entries listed by the    ----vvvv flag    excludes the
  3538.       number of table entries needed to determine what rule    has
  3539.       been matched.     The number of entries is equal    to the number
  3540.       of DFA states    if the scanner does not    use RRRREEEEJJJJEEEECCCCTTTT,,,, and
  3541.       somewhat greater than    the number of states if    it does.
  3542.  
  3543.       RRRREEEEJJJJEEEECCCCTTTT cannot    be used    with the ----ffff or ----FFFF options.
  3544.  
  3545.       The _f_l_e_x internal algorithms need documentation.
  3546.  
  3547.      SSSSEEEEEEEE AAAALLLLSSSSOOOO
  3548.       lex(1), yacc(1), sed(1), awk(1).
  3549.  
  3550.       John Levine, Tony Mason, and Doug Brown, _L_e_x & _Y_a_c_c,
  3551.       O'Reilly and Associates.  Be sure to get the 2nd edition.
  3552.  
  3553.       M. E.    Lesk and E. Schmidt, _L_E_X - _L_e_x_i_c_a_l _A_n_a_l_y_z_e_r _G_e_n_e_r_a_t_o_r
  3554.  
  3555.       Alfred Aho, Ravi Sethi and Jeffrey Ullman, _C_o_m_p_i_l_e_r_s:
  3556.       _P_r_i_n_c_i_p_l_e_s, _T_e_c_h_n_i_q_u_e_s _a_n_d _T_o_o_l_s, Addison-Wesley (1986).
  3557.       Describes the    pattern-matching techniques used by _f_l_e_x
  3558.  
  3559.  
  3560.  
  3561.      Page 54                         (printed 5/18/98)
  3562.  
  3563.  
  3564.  
  3565.  
  3566.  
  3567.  
  3568.      FFFFLLLLEEEEXXXX((((1111))))         VVVVeeeerrrrssssiiiioooonnnn 2222....5555 ((((AAAApppprrrriiiillll 1111999999995555))))           FFFFLLLLEEEEXXXX((((1111))))
  3569.  
  3570.  
  3571.  
  3572.       (deterministic finite    automata).
  3573.  
  3574.      AAAAUUUUTTTTHHHHOOOORRRR
  3575.       Vern Paxson, with the    help of    many ideas and much
  3576.       inspiration from Van Jacobson.  Original version by Jef
  3577.       Poskanzer.  The fast table representation is a partial
  3578.       implementation of a design done by Van Jacobson.  The
  3579.       implementation was done by Kevin Gong    and Vern Paxson.
  3580.  
  3581.       Thanks to the    many _f_l_e_x beta-testers,    feedbackers, and
  3582.       contributors,    especially Francois Pinard, Casey Leedom,
  3583.       Robert Abramovitz, Stan Adermann, Terry Allen, David
  3584.       Barker-Plummer, John Basrai, Neal Becker, Nelson H.F.    Beebe,
  3585.       benson@odi.com, Karl Berry, Peter A. Bigot, Simon Blanchard,
  3586.       Keith    Bostic,    Frederic Brehm,    Ian Brockbank, Kin Cho,    Nick
  3587.       Christopher, Brian Clapper, J.T. Conklin, Jason Coughlin,
  3588.       Bill Cox, Nick Cropper, Dave Curtis, Scott David Daniels,
  3589.       Chris    G. Demetriou, Theo Deraadt, Mike Donahue, Chuck
  3590.       Doucette, Tom    Epperly, Leo Eskin, Chris Faylor, Chris
  3591.       Flatters, Jon    Forrest, Jeffrey Friedl, Joe Gayda, Kaveh R.
  3592.       Ghazi, Wolfgang Glunz, Eric Goldman, Christopher M. Gould,
  3593.       Ulrich Grepel, Peer Griebel, Jan Hajic, Charles Hemphill,
  3594.       NORO Hideo, Jarkko Hietaniemi, Scott Hofmann,    Jeff Honig,
  3595.       Dana Hudes, Eric Hughes, John    Interrante, Ceriel Jacobs,
  3596.       Michal Jaegermann, Sakari Jalovaara, Jeffrey R. Jones, Henry
  3597.       Juengst, Klaus Kaempf, Jonathan I. Kamens, Terrence O    Kane,
  3598.       Amir Katz, ken@ken.hilco.com,    Kevin B. Kenny,    Steve Kirsch,
  3599.       Winfried Koenig, Marq    Kole, Ronald Lamprecht,    Greg Lee,
  3600.       Rohan    Lenard,    Craig Leres, John Levine, Steve    Liddle,    David
  3601.       Loffredo, Mike Long, Mohamed el Lozy,    Brian Madsen, Malte,
  3602.       Joe Marshall,    Bengt Martensson, Chris    Metcalf, Luke Mewburn,
  3603.       Jim Meyering,    R. Alexander Milowski, Erik Naggum, G.T.
  3604.       Nicol, Landon    Noll, James Nordby, Marc Nozell, Richard
  3605.       Ohnemus, Karsten Pahnke, Sven    Panne, Roland Pesch, Walter
  3606.       Pelissero, Gaumond Pierre, Esmond Pitt, Jef Poskanzer, Joe
  3607.       Rahmeh, Jarmo    Raiha, Frederic    Raimbault, Pat Rankin, Rick
  3608.       Richardson, Kevin Rodgers, Kai Uwe Rommel, Jim Roskind,
  3609.       Alberto Santini, Andreas Scherer, Darrell Schiebel, Raf
  3610.       Schietekat, Doug Schmidt, Philippe Schnoebelen, Andreas
  3611.       Schwab, Larry    Schwimmer, Alex    Siegel,    Eckehard Stolz,    Jan-
  3612.       Erik Strvmquist, Mike    Stump, Paul Stuart, Dave Tallman, Ian
  3613.       Lance    Taylor,    Chris Thewalt, Richard M. Timoney, Jodi    Tsai,
  3614.       Paul Tuinenga, Gary Weik, Frank Whaley, Gerhard Wilhelms,
  3615.       Kent Williams, Ken Yap, Ron Zellar, Nathan Zelle, David
  3616.       Zuhn,    and those whose    names have slipped my marginal mail-
  3617.       archiving skills but whose contributions are appreciated all
  3618.       the same.
  3619.  
  3620.       Thanks to Keith Bostic, Jon Forrest, Noah Friedman, John
  3621.       Gilmore, Craig Leres,    John Levine, Bob Mulcahy, G.T.    Nicol,
  3622.       Francois Pinard, Rich    Salz, and Richard Stallman for help
  3623.       with various distribution headaches.
  3624.  
  3625.  
  3626.  
  3627.      Page 55                         (printed 5/18/98)
  3628.  
  3629.  
  3630.  
  3631.  
  3632.  
  3633.  
  3634.      FFFFLLLLEEEEXXXX((((1111))))         VVVVeeeerrrrssssiiiioooonnnn 2222....5555 ((((AAAApppprrrriiiillll 1111999999995555))))           FFFFLLLLEEEEXXXX((((1111))))
  3635.  
  3636.  
  3637.  
  3638.       Thanks to Esmond Pitt    and Earle Horton for 8-bit character
  3639.       support; to Benson Margulies and Fred    Burke for C++ support;
  3640.       to Kent Williams and Tom Epperly for C++ class support; to
  3641.       Ove Ewerlid for support of NUL's; and    to Eric    Hughes for
  3642.       support of multiple buffers.
  3643.  
  3644.       This work was    primarily done when I was with the Real    Time
  3645.       Systems Group    at the Lawrence    Berkeley Laboratory in
  3646.       Berkeley, CA.     Many thanks to    all there for the support I
  3647.       received.
  3648.  
  3649.       Send comments    to vern@ee.lbl.gov.
  3650.  
  3651.  
  3652.  
  3653.  
  3654.  
  3655.  
  3656.  
  3657.  
  3658.  
  3659.  
  3660.  
  3661.  
  3662.  
  3663.  
  3664.  
  3665.  
  3666.  
  3667.  
  3668.  
  3669.  
  3670.  
  3671.  
  3672.  
  3673.  
  3674.  
  3675.  
  3676.  
  3677.  
  3678.  
  3679.  
  3680.  
  3681.  
  3682.  
  3683.  
  3684.  
  3685.  
  3686.  
  3687.  
  3688.  
  3689.  
  3690.  
  3691.  
  3692.  
  3693.      Page 56                         (printed 5/18/98)
  3694.  
  3695.  
  3696.  
  3697.